Hello C experts,

main() {


int i=0;
int x;
fork();
fork();
fork();
i++;
x=&i;
printf("%d %x\n",i,x);
}

Each child process gets its own copy of i , but why does x not print different address ?

Because with virtual memory every user process gets the same address range but different physical memory links...so every process appears to have the same memory but in reality it has its own copy of things like data...Note: most programs will shared some blocks of code i.e. Dlls and the text section of code can be shared..

As an experiment try changing the child processes x value and then display it....add x to the pid and then display it

commented: Thanks. +6

your code does not seem t be running...