GateAI
Programming in C

GATE CSE 2023 · Q35

NAT1 markEasy

Time

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 ", (x+y)); return 0; }

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 7

Programming in C

Let us trace the execution of the program step by step:

  1. Inside funcp(), the variable x is declared as static int x = 1;. A static local variable retains its value between successive function calls and is initialized only once.

  2. In main(), local variables x and y are declared.

  3. The statement x = funcp(); executes:

    • Inside funcp(), x is incremented from 11 to 22 (x++).

    • funcp() returns 22.

    • The local variable x in main is assigned the value 22.

  4. The statement y = funcp() + x; executes:

    • The second call to funcp() increments the static variable x from 22 to 33.

    • funcp() returns 33.

    • The local variable x in main is still 22.

    • Therefore, y=3+2=5y = 3 + 2 = 5.

  5. The statement `printf("%d

", (x+y));` prints:

x+y=2+5=7x + y = 2 + 5 = 7

Thus, the printed integer value is 7.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Programming in C previous year question is Q35 of the GATE CSE 2023 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 16 of them are 1-mark NAT questions like this one, and it is the only one in GATE CSE 2023.

How GATE tests Programming in C

More from GATE CSE 2023

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2023 · Q35 · NAT

The integer value printed by the ANSI-C program given below is … #include int funcp(){ static int x = 1; x++; return x; } int main(){ int x,y; x = funcp(); y = funcp()+x; printf("%d ", (x+y)); return 0; }

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.