GATE CS 2023 | Question 35

Programming & Data Structures › Basics & Control Structures · NAT · 1 mark · Answer: 7

  1. Question 35Programming & Data Structuresnat1 mark
    The integer printed by the C program (funcp uses static int x=1; x++; return x;, called twice in main) is __________
    int funcp(){ static int x = 1; x++; return x; }
    int main(){
       int x,y;
       x = funcp();
       y = funcp()+x;
       printf("%d\n", (x+y));
    }

    Answer: 7

    Solution

    Answer: 7 x = funcp(): static x becomes 2, returns 2, so x=2. y = funcp()+x: static x becomes 3, returns 3, so y=3+2=5. Print x+y = 2+5 = 7.

More GATE PYQ on Basics & Control Structures

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2023 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →