I just can't figure out why this code works the way it does (rather than I'd expect):
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> #include <sys/types.h> int main() { int buffer; int* address; address=&buffer; if(fork()==0) { *address=27; printf("Address %ld stores %d\n",(long)address,*address); exit(0); } wait(NULL); printf("Address %ld stores %d\n",(long)(&buffer),buffer); return 0; } Why does the system store different variables even if they're pointed to the same memory address?
NOTE: I never really expected this code to work, since otherwise the whole bunch of pipes and stuff wouldn't make any sense; I'd just like to understand what's going on here.
bufferand that is what I get: ideone.com/ESqx1I