This program TOTAL_ELEMENTScomputes correctly if not used in a for loop. And the first printf prints correctly. But why does the second printf not work, even if the condition in the loop is true. TOTAL_ELEMENTSreturns 7. And -1<7-2ie -1<5true. So what is wrong here?
#include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};
int main()
{
int d;
printf("Total= %d\n", TOTAL_ELEMENTS);
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);
return 0;
}
source
share