Tuesday, March 22, 2005

cool code....

check this code out....(go to the basics of c to find the answer).. someone asked it on blug-prog:

using namespace ::std;

int main()
pid_t child_pid;
printf(" hello world !! \n");
child_pid = fork();

(i have used "" instead of greater than sign as my blog editor had trouble workin with them... thats why cout was changed to printf)

if u put the "\n", u'll get one "hello world !!" as output but if u remove the endl u'll get two "hello world!!" as output... reason being that the programs are not flushing the buffers and the child is inheriting unflushed buffer...causing it to print it twice( as told by Imidi kiran on blug)....

this stuff was cool...

No comments:

Post a Comment