-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmemory_1.c
38 lines (34 loc) · 1.23 KB
/
memory_1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Author: NagaChaitanya Vellanki
*
*
* Sample output:
* 0x601000 before malloc calls
* program break after malloc call 0x622000
* program break after malloc call 0x622000
* program break after malloc call 0x622000
* Address of i: 0x601010
* Address of j: 0x601030
* Address of k: 0x601060
* Difference between i, j addresses: 32
* Difference between j, k addresses 48
* Difference between address i, sbrk(0): 135152
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int *i, *j, *k;
printf("%p before malloc calls\n", sbrk(0));
i = (int *) malloc(sizeof(int));
printf("program break after malloc call %p\n", sbrk(0));
j = (int *) malloc(10 * sizeof(int));
printf("program break after malloc call %p\n", sbrk(0));
k = (int *) malloc(sizeof(int));
printf("program break after malloc call %p\n", sbrk(0));
printf("Address of i: %p\nAddress of j: %p\nAddress of k: %p\nDifference between i, j addresses: %ld\nDifference between j, k addresses: %ld\nDifference between address i, sbrk(0): %ld\n", (void *)i, (void *)j, (void *)k, (char *) j - (char *) i, (char *)k - (char *)j, (char *) sbrk(0) - (char *)i);
free(i);
free(j);
free(k);
exit(EXIT_SUCCESS);
}