470 views
0 votes
0 votes
main(){

int i,n;

 for(int i=0;i<n;i++){

fork();

printf("*");

}

}

How many times ‘*’ will be printed? The answer is not 2^n ? why?

1 Answer

0 votes
0 votes
each time the for loop gets executed it prints star(*) two times

=> cuz fork() creates one child and it prints one star and when the control comes back to parent it prints * again

so for n loop executions the answer should be => 2n

Related questions

0 votes
0 votes
1 answer
1
Erwin Smith asked Apr 11, 2023
782 views
void main() { int n = 1; if(fork()==0) { n = n<<1; printf(“%d, “, n); n = n <<1; } if(fork()==0) n=n+700; printf(“%d, “,n); }Which of the following output is not ...
2 votes
2 votes
3 answers
4
Philosophical_Virus asked Dec 10, 2023
884 views
Int main (){fork();printf("a");fork();printf("b");return 0;}How many distinct outputs are possible of above code? And also give outputs