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 is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;

12 Answers   TCS,


write a sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?

0 Answers  


‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

0 Answers  


main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(“%d”,x); }

6 Answers   Vector,


what is the difference between const volatile int i & volatile const int j;

2 Answers   HCL,






any string of bits of length 'n' represents a unique non- negative integer between.............?

2 Answers  


A C E G H +B D F A I ------------ E F G H D

1 Answers   Infosys,


What is the difference between char a[] = "string"; and char *p = "string"; ?

14 Answers   Adobe, TCS, Honeywell,


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

0 Answers   Lovely Professional University,


Find greatest of two numbers using macro

4 Answers   Siemens, Bosch,


what are the stoge class in C and tel the scope and life time of it?

2 Answers   Tech Mahindra,


how to write a cprogram yo get output in the form * *** ***** ******* ********* ******* ***** *** *

3 Answers  






Categories