Why does calling sbrk(0) twice give a different value?
I'm trying to understand the sbrk() function. From what I know: sbrk(0) returns the current address of the break and doesn't increment it. sbrk(size) increments the address of the break by size bytes and returns the previous address of the break. So I created something to test it: #include <unistd.h> #include <stdio.h> int main(void) { printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(5) = %p\n", sbrk(5)); // should return value x printf("sbrk(0) = %p\n", sbrk(0)); // should return value x + 5 } So I'm expecting