Open In App

GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 26

Like Article
Like
Save
Share
Report

A process executes the following code:




#include <stdio.h> 
#include <unistd.h>  
  
int main() 
    if (fork() && (!fork())) { 
        if (fork() || fork()) { 
            fork(); 
        
    
    int i=1;
    printf("i++");  
    return 0; 


Output of the above program is

(A) i++i++i++i++i++i++i++
(B) 1 2 3 4 5
(C) 1 1 1 1 1
(D) None of these


Answer: (A)

Explanation: Printed output:

i++i++i++i++i++i++i++




#include <stdio.h> 
#include <unistd.h>  
  
int main() 
    if (fork() && (!fork())) { 
        if (fork() || fork()) { 
            fork(); 
        
    
    int i=1;
    printf("i++");  
    return 0; 


Option (A) is correct.

Quiz of this Question



Last Updated : 06 Nov, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads