that is because output is buffered.
when printf("hello") is executed, "hello" goes to the output buffer and it
waits for a new line
after fork there will be two instances of the program and both will output
"helloworld"
try putting a new line in the first printf statement, you will get expected
output,it has nothing to do with fork, read about buffered input output On Tue, Jan 17, 2012 at 3:56 PM, himanshu kansal < [email protected]> wrote: > #include<stdio.h> > int main() > { printf("hello"); > fork(); > printf("world"); > } > > > what will be the o/p.... > > on my system...its showing hello world hello world... > > but i think it could be hello world two times in any order..... > > please tell me what is the exact o/p... > > i have a little confusion also that whether child process starts > executing from start of the main() or whether it starts from the line > following the fork() command..... > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
