in the below code i am trying to add two elements of array with the increment operator, but i am getting the output sum to be wrong. kindly help me if i made any mistake in the code
#include <stdio.h>
int main(void) {
int a[2];
int top=-1;
a[++top]=10;
a[++top]=20;
printf("a0 is %d \n",a[0]);
printf("a1 is %d \n",a[top]);
printf("value of sum is %d \n",a[top]+a[--top]);
}
the output of last line should be 30 as i and summing the two values in a array. but the out put i get is as follows
a0 is 10
a1 is 20
value of sum is 20