The value printed by the following program is __________________ . void f (int…

2016

The value printed by the following program is __________________ .

    void f (int * p, int m) {
  m = m + 5;
  *p = *p + m;
  return;
}
  void main () {
  int i=5, j=10;
  f (&i, j);
  printf ("%d", i+j);
  }

Attempted by 154 students.

Show answer & explanation

Correct answer: 30

Answer: 30.

  • Initial values: i = 5, j = 10.

  • Call f(&i, j): the parameter m receives a copy of j (so m = 10). The pointer p refers to i.

  • Inside f: m = m + 5 makes m = 15.

  • Then *p = *p + m adds m to i: i = 5 + 15 = 20.

  • After return: i = 20 and j is still 10, so printf("%d", i + j) prints 20 + 10 = 30.

Final result: 30

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

Explore the full course: Gate Guidance By Sanchit Sir