GATE 2023 CS – Question 35
The integer value printed by the ANSI-C program given below is ______.
#include<stdio.h>
int funcp(){
static int x = 1;
x++;
return x;
}
int main(){
int x,y;
x = funcp();
y = funcp()+x;
printf("%d\n", (x+y));
return 0;
}Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 7
Explanation
The static x persists across calls. The first call returns 2, so x=2. The second call returns 3, so y=3+2=5. The program prints x+y=7.