Consider the following C program:
#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 _______
View worked solution
Answer: 10
The array a is initialized as {2, 4, 6, 8, 10}. The pointer b is initialized to a + 4, which points to the last element a[4]. Thus, *b = 10 remains constant throughout the execution.
The loop runs for to . In each iteration, the sum is updated as:
Let's trace each iteration step-by-step:
- :
- :
- :
- :
- :
Therefore, the final output printed by the program is 10.
Free practice · Your answers on this page are not saved.
