StreakPeaked· Practice

ExamsGATETechnical

#include <stdio.h> void foo(int *p, int x){ *p=x; } int main(){ int *z; int a = 20, b = 25; z = &a; foo(z,b); printf("%d",a); return 0; } The output of the given C program is _________. (A answer in integer)

  1. 20
  2. 25
  3. 0
  4. Compilation error

Correct answer: 25

Solution

The function 'foo' takes a pointer and an integer, assigning the integer value to the location pointed to by the pointer. Since 'z' points to 'a' and 'foo' sets '*p' (which is 'a') to 'b' (25), the value of 'a' is updated to 25, resulting in the output.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →