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();
}
Answers were Sorted based on User's Feedback
Answer / raghu
totally 8 processes...so each process will print 0 & 1
output: 0101010101010101
Is This Answer Correct ? | 6 Yes | 1 No |
Answer / sourisengupta
finally we will get 001111.
for the first fork() two 0 will be printed and for secoond
forkk four 1 will be printed.
Is This Answer Correct ? | 4 Yes | 3 No |
Answer / 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 |
Answer / vignesh1988i
for first printf it will print 0, for second printf it will
print 1.. and finally i will have a value 2.
Is This Answer Correct ? | 5 Yes | 5 No |
Can you mix old-style and new-style function syntax?
What do you mean by keywords in c?
You have an array of n integers, randomly ordered with value 1 to n-1.The array is such that there is only one and one value occurred twice. How will you find this number?
Explain the use of fflush() function?
What is the difference b/w Structure & Union?
how to find the size of the data type like int,float without using the sizeof operator?
ASCII stands for
Find greatest number out of 10 number without using loop.
Was 2000 a leap year?
write a code for large nos multilication (upto 200 digits)
What does != Mean in c?
What does d mean?