StreakPeaked· Practice

ExamsGATETechnical

Consider the following C program: ```c #include <stdio.h> int main() { int a[] = {2, 4, 6, 8, 10}; int i, sum = 0, *b = a + 4; for (i = 0; i < 5; i++) sum = sum + (*b - i) - *(b - i); printf("%d\n", sum); return 0; } ``` The output of the above C program is __________.

  1. 0
  2. 2
  3. 4
  4. 6

Correct answer: 0

Solution

Here `b = a + 4`, so `*b = a[4] = 10`. For each `i`, the term becomes `(10 - i) - a[4-i]`, and the five terms are `0, 1, 2, 3, 4` minus the corresponding array values `10, 8, 6, 4, 2`, which sum to zero overall. Hence the program prints `0`.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →