GateAI
Programming in C

GATE CSE 2025 Set 2 · Q62

NAT2 marksEasy

Time

Consider the following C program:#include <stdio.h> int main() { int a; int arr[5] = {30,50,10}; int *ptr; ptr = &arr[0] + 1; a = *ptr; (*ptr)++; ptr++; printf("%d", a + (*ptr) + arr[1]); return 0; }The output of the above program is ________. (Answer in integer)

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 111

Programming in C

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

  1. Array Initialization:int arr[5] = {30, 50, 10}; initializes the array with:

    • arr[0] = 30

    • arr[1] = 50

    • arr[2] = 10

    • arr[3] = 0

    • arr[4] = 0

  2. Pointer Initialization:ptr = &arr[0] + 1; points ptr to arr[1] (the address of the element at index 1).

  3. Assignment to aa:a = *ptr; assigns the value of *ptr (which is arr[1] = 50) to a. Thus, a=50a = 50.

  4. Incrementing Value:(*ptr)++; increments the value stored at the address pointed to by ptr. Since ptr points to arr[1], the value of arr[1] becomes 50+1=5150 + 1 = 51.

  5. Pointer Increment:ptr++; increments the pointer itself, so ptr now points to arr[2]. Therefore, *ptr is now arr[2] = 10.

  6. Printing the Result: The expression to evaluate is a + (*ptr) + arr[1]:

    Value=50+10+51=111\text{Value} = 50 + 10 + 51 = 111

Thus, the output of the program is 111.

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 Q62 of the GATE CSE 2025 Set 2 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. 17 of them are 2-mark NAT questions like this one, and GATE CSE 2025 Set 2 has 4.

How GATE tests Programming in C

More from GATE CSE 2025 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2025 Set 2 · Q62 · NAT

Consider the following C program: #include int main() { int a; int arr[5] = {30,50,10}; int *ptr; ptr = &arr[0] + 1; a = *ptr; (*ptr)++; ptr++; printf("%d", a + (*ptr) + arr[1]); return 0; } The output of the above program is … (Answer in integer)

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.