Consider the following code fragment: if (fork() == 0) { a = a + 5;…

2005

Consider the following code fragment:

  if (fork() == 0)
  {
    a = a + 5;
    printf(“%d,%d\\n”, a, &a);
  }
  else
  { 
   a = a –5; 
   printf(“%d, %d\\n”, a, &a);
  } 

Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?

  1. A.

    u = x + 10 and v = y

  2. B.

    u = x + 10 and v != y

  3. C.

    u + 10 = x and v = y

  4. D.

    u + 10 = x and v != y

Attempted by 52 students.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir