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

What does d mean?

0 Answers  


What is assignment operator?

0 Answers  


what is ur strangth & weekness

0 Answers   Cognizant, LG Soft, NetEnrich,


Is c compiled or interpreted?

0 Answers  


Should I learn c before c++?

0 Answers  






Why is structure padding done in c?

0 Answers  


Write a Program to accept different goods with the number, price and date of purchase and display them

0 Answers   HDFC,


What is the memory allocated by the following definition ? int (*x)[10];

4 Answers   ADITI, Wipro,


what is ANSI and ISO

7 Answers   HCL,


write a program to gat the digt sum of a number (et. 15= >1+5=6)

2 Answers  


Why is extern used in c?

0 Answers  


What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?

0 Answers  


Categories