My understanding is that malloc internally uses sbrk() and sbrk(0) gives pointer to current location of the program break. then according to following code :-
#include<stdio.h>
#include<malloc.h>
int main()
{
printf("Before allocation :- %u\n",sbrk(0));
int *ptr = malloc(sizeof(int)*100);
printf("After Allocation of 400Bytes :- %u\n",sbrk(0));
free(ptr);
printf("After free() :- %u\n",sbrk(0));
return 0;
}
output is :
Before allocation :- 37367808
After Allocation of 400Bytes :- 37502976
After free() :- 37502976
But after call of free() it should print again 37367808
instead it is printing 37502976
.