I am trying to understand how memory works in C, so am experimenting with the sbrk
function now. I know that sbrk(0)
should return the current program break, that is the end of the data segment.
So I tried to call sbrk(0)
multiple times and for some reason I get the first value different than the other values. For example, this program
#include <stdio.h>
#include <unistd.h>
int main()
{
void * currpb = sbrk(0);
printf("The current program break is: %p.\n", currpb);
void * newpb = sbrk(0);
printf("The current program break is: %p.\n", newpb);
void *new2pb = sbrk(0);
printf("The current program break is: %p.\n", new2pb);
void *new3pb = sbrk(0);
printf("The current program break is: %p.\n", new3pb);
}
Give me the following output:
The current program break is: 0x18b0000.
The current program break is: 0x18d1000.
The current program break is: 0x18d1000.
The current program break is: 0x18d1000.
Am not sure why the 1st value is different than the other three values, any ideas?