Possible Duplicate:
Working of fork() in linux gcc
Why does this code print two times?
I want to know the reason behind the output of the below code:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
FILE *fp;
int n;
printf("%d",45);
//fflush(stdout);
if((n=fork())>0){
printf("in parent\n");
exit(0);
}
else if(n==0)
printf("%d",45);
}
Output is
45inparent
4545
If I use fflush, then output is
45inparent
45
Also, I am running on the linux platform