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

c programming of binary addition of two binary numbers

4 Answers  


When should structures be passed by values or by references?

0 Answers   Adobe,


What is false about the following A compound statement is a.A set of simple statments b.Demarcated on either side by curly brackets c.Can be used in place of simple statement d.A C function is not a compound statement.

5 Answers   CCEM, TCS,


What will the preprocessor do for a program?

0 Answers   Aspire, Infogain,


Why are algorithms important in c program?

0 Answers  






A marketing company wishes to construct a decision table to decide how to treat clients according to three characteristics: Gender, City Dweller, and age group: A (under 30), B (between 30 and 60), C (over 60). The company has four products (W, X, Y and Z) to test market. Product W will appeal to female city dwellers. Product X will appeal to young females. Product Y will appeal to Male middle aged shoppers who do not live in cities. Product Z will appeal to all but older females.

2 Answers  


how would a 4*3 array A[4][3] stored in Row Major Order?

0 Answers   HCL, Ignou,


What is the use of a static variable in c?

0 Answers  


write a statement to display all the elements array M(in reverse order? int M[8]={20,21,22,23,24,25,26,27};

5 Answers  


Is multithreading possible in c?

0 Answers  


List the variables are used for writing doubly linked list program.

0 Answers   Infosys, Wipro,


Is it better to bitshift a value than to multiply by 2?

0 Answers  


Categories