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



What is the output of the following program #include<stdio.h> main() { i..

Answer / raghu

totally 8 processes...so each process will print 0 & 1
output: 0101010101010101

Is This Answer Correct ?    6 Yes 1 No

What is the output of the following program #include<stdio.h> main() { i..

Answer / kracekumar

01010101010101

Is This Answer Correct ?    2 Yes 0 No

What is the output of the following program #include<stdio.h> main() { i..

Answer / vignesh1988i

01 finally i will have 2

Is This Answer Correct ?    4 Yes 3 No

What is the output of the following program #include<stdio.h> main() { i..

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

What is the output of the following program #include<stdio.h> main() { i..

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

What is the output of the following program #include<stdio.h> main() { i..

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

What is the output of the following program #include<stdio.h> main() { i..

Answer / vijay r15

error undefined
function fork and wait

Is This Answer Correct ?    2 Yes 3 No

What is the output of the following program #include<stdio.h> main() { i..

Answer / guest

0101010101

Is This Answer Correct ?    3 Yes 6 No

Post New Answer

More C Interview Questions

Can you mix old-style and new-style function syntax?

0 Answers  


What do you mean by keywords in c?

0 Answers  


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?

1 Answers  


Explain the use of fflush() function?

0 Answers  


What is the difference b/w Structure & Union?

3 Answers  






how to find the size of the data type like int,float without using the sizeof operator?

13 Answers  


ASCII stands for

1 Answers  


Find greatest number out of 10 number without using loop.

5 Answers   TCS,


Was 2000 a leap year?

0 Answers  


write a code for large nos multilication (upto 200 digits)

2 Answers   Persistent,


What does != Mean in c?

0 Answers  


What does d mean?

0 Answers  


Categories