GATE 2025 CS (CS2) – Question 62
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)
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 111
Explanation
ptr points to arr[1], so a = 50, then arr[1] becomes 51. After ptr++, *ptr = arr[2] = 10. The output is 50 + 10 + 51 = 111.