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 |
Are bit fields portable?
The difference between printf and fprintf is ?
Convert a distance from miles to kilometers .there are 5280 feets per mile,12 inches per foot .2.54 centimeters per inch and 100000centimeters per kilometer
There is a number and when the last digit is moved to its first position the resultant number will be 50% higher than the original number.Find the number?
What is difference between structure and union in c?
15.what is the disadvantage of using macros? 16.what is the self-referential structure? 17.can a union be self-referenced? 18.What is a pointer? 19.What is the Lvalue and Rvalue? 20.what is the difference between these initializations? 21.Char a[]=”string”; 22.Char *p=”literal”; 23.Does *p++ increment p, or what it points to?
What is alloca() and why is its use discouraged?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
write a program to find the frequency of a number
What is an auto keyword in c?
what will be maximum number of comparisons when number of elements are given?
write a program to concatenation the string using switch case?