retagged by
4,628 views
9 votes
9 votes

A process execute the code:
 

main()
{
    fork();
    fork() && fork() || fork();
    fork();
    printf("Hi");
}  



The number of times "Hi" will be printed is

retagged by

2 Answers

Best answer
13 votes
13 votes

Basic points : -

1) && ===> if left side operand evaluates to 0 then right side operator doesn't evaluate

2) ||   ===> if left side operand evaluates to 1 then right side operator doesn't evaluate

3) fork() ====> Doubling the processes ( one parent copy and one child copy )

4) Precedence of && is grater than precedence of ||

 fork() && fork() || fork() equivalent to  ( fork() && fork() ) || ( fork() ) , note that result of this statement doesn't used for next statement

 

for better clarity of image https://drive.google.com/drive/folders/1aji_OQGkDY9atCk6zwGhl5dYeMWXMm-c

selected by

Related questions

2 votes
2 votes
3 answers
1
Philosophical_Virus asked Dec 10, 2023
767 views
Int main (){fork();printf("a");fork();printf("b");return 0;}How many distinct outputs are possible of above code? And also give outputs
0 votes
0 votes
1 answer
2
Erwin Smith asked Apr 11, 2023
756 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 ...
0 votes
0 votes
2 answers
4
dd asked Sep 15, 2018
1,029 views
The fork system call creates new entries in the open file table for the newly created child process. [True / False][ what is open file table ? ]