The number of 3’s in the output of the program — main() { printf("1"); fork();…

2018

The number of 3’s in the output of the program — main() { printf("1"); fork(); printf("2"); fork(); fork(); printf("3"); }

  1. A.

    16

  2. B.

    8

  3. C.

    4

  4. D.

    2

Attempted by 369 students.

Show answer & explanation

Correct answer: B

Each fork() doubles the number of processes. After first fork() → 2 processes

After second fork() → 4 processes

After third fork() → 8 processes

Each of the 8 processes executes printf("3") once. 👉 Number of 3s printed = 8

Explore the full course: Up Lt Grade Assistant Teacher 2025