You know #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) returns an unsigned number, and -1 may become the largest number, because it converts to a unsigned number.
And you can test the expression "printf("%d\n", -1 < TOTAL_ELEMENTS);"; it prints 0. So we can solve by adding (int) before (TOTAL_ELEMENTS - 2) or alter the loop:
for (int d = 0; d < TOTAL_ELEMENTS; d++) {
printf("%d\n", array[d]); }
And I don't think making the d
variable dependent is a good way, because d
is a variable in for
loop.