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 many main () function we can have in a project?
What is double pointer in c?
#include<stdio.h> int main(){ int i=10; int *ptr=&i; *ptr=(int *)20; printf("%d",i); return 0; } Output: 20 can anyone explain how came the output is 20
What is build process in c?
What is RAM memory? and What is ROM?Who designed one is temparary and another is permanent?why they designed like that?By using far pointer which type data(whether hexadecimal)we can access?
Was 2000 a leap year?
Can a variable be both const and volatile?
What is #line used for?
How can you find the day of the week given the date?
the maximum value that an integer constant can have is a) -32767 b) 32767 c) 1.701e+38 d) -1.7014e+38
Explain how does free() know explain how much memory to release?
what is inline function?