GATE Assistant

Past questions › Computer Science and Information Technology › GATE 2026 set1

GATE 2026 set1 · CS · NAT · 2 marks · Operating System › Processes & Threads

GATE 2026 set1 Computer Science and Information Technology question: Consider the following program snippet. Assume that the program compiles and runs…

Consider the following program snippet. Assume that the program compiles and runs successfully. Further, assume that the fork() system call is always successful in creating a process.

int main () {
   int i;
   for (i = 0; i < 3; i++){
      if (fork() == 0){
        continue;
      }
      break;
   }
   printf("Hello!");
   return 0;
}

The total number of times that the printf statement gets executed is ________. (answer in integer)

Show answer

Official answer: 4

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion