Skip to main content

GATE CSE 2025Programming in C › Pointers, Arrays & StringsVerified

GATE CSE 2025 PYQ: #include <stdio.h> void foo ( int * p , int x ) { * p = x ; } int main (){ int * z ; int a = 20 , b = 25 ; z…

 

  1. #include <stdio.h>
  2. void foo(int *p, int x) {
  3. *p=x;
  4. }
  5. int main(){
  6. int *z;
  7. int a = 20, b = 25;
  8. z = &a;
  9. foo(z,b);
  10. printf("%d",a);
  11. return 0;
  12. }

The output of the given C\text{C} program is __________. (Answer in integer)

    Answer

    25

    Approach

    Trace the C program: z is assigned the address of a, then foo receives that address and the integer value b. Inside foo, the pointer dereference writes b's value into a, so the printf sees the updated value of a.

    The function foo modifies the variable a through the pointer z, setting it to the value of b (25). Therefore the output is 25.

    Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.