What is the output of the following program

#include<stdio.h>
main()
{
int i=0;
fork();
printf("%d",i++);
fork();
printf("%d",i++);
fork();
wait();
}

Answer Posted / srikanth

print order cannot be predicted.Total 8 process(including
main) first process prints 0,1
the first child prints 0,1 and the other 2 child/grand child
process print 1's (two 1s). The other four child/grand child
process wont print anything (created after printf)

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is action and transformation in spark?

579


List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.

2291


What is size of union in c?

567


What is sizeof array in c?

578


How does placing some code lines between the comment symbol help in debugging the code?

528






Write a code to determine the total number of stops an elevator would take to serve N number of people.

717


Explain what are run-time errors?

595


Place the #include statement must be written in the program?

555


What is meant by type casting?

610


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

1988


which is conditional construct a) if statement b) switch statement c) while/for d) goto

726


What are types of functions?

551


What are inbuilt functions in c?

551


What does main () mean in c?

603


Describe newline escape sequence with a sample program?

635