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 |
How can variables be characterized?
Develop a flow chart and write a c program to find the roots of a quadratic equation ax2+bx+c=0 using switch and break statement.
Why Modern OS are interrupt driven?Give an example
I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.
Write a c program to build a heap method using Pointer to function and pointer to structure ?
why in C,C++'s int size is 2 byte and .net(c#) int Size is 4 byte?
write a program which will count occurance of a day between two dates.
What is scope of variable in c?
Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.
what is the use of call back function in c?tell me with example
What is the difference between printf and scanf in c?
What is the process of writing the null pointer?