#include<stdio.h>
main()
{
int a=9;
printf(" %u hiii \n",&a);
int p=fork();
if(p==0){
a=10;
printf("\nChild %u \n Value in child of a = %d\n",&p,a);
}
else
printf("\nvalue of a = %d \n Parent with child process id = %d address of p = %u \n",a,p,&p);
}
Ouptut of the above program According to ideone.com is - >
3215698376 hiii
value of a = 9
Parent with child process id = 28150 address of p = 3215698380
3215698376 hiii
Child 3215698380
Value in child of a = 10
My question is if both are processes are giving same addresses of variable 'a' then if I change the value the value in one process why isn't the change reflecting in Parent process. Moreover why the child process is running whole program else it should run with statements after fork().