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? Operating System programming-in-c operating-system + – vikranty2j asked Mar 20, 2023 vikranty2j 470 views answer comment Share Follow See all 3 Comments See all 3 3 Comments reply chinmay_rajpurohit commented Mar 20, 2023 reply Follow Share It will vary. Check for n=1,2,3. If you checked this please give what expression you are getting. I am not getting any fixed expression 0 votes 0 votes vikranty2j commented Mar 21, 2023 reply Follow Share I am getting this expression. 2^(n+1)-2 0 votes 0 votes chinmay_rajpurohit commented Mar 23, 2023 reply Follow Share getting correct for n=4?? too. if yes then I think this correct 0 votes 0 votes Please log in or register to add a comment.
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 kickassakash answered Mar 21, 2023 kickassakash comment Share Follow See 1 comment See all 1 1 comment reply vikranty2j commented Mar 21, 2023 reply Follow Share No this is not the right answer. Let say n=3 ,then I will be getting 14 stars. I think the general expression is 2^(n+1)-2. I don’t know why. –1 votes –1 votes Please log in or register to add a comment.