Within the conditional expression of the for loop
for (i = -1; i < sizeof(array) / sizeof(int); i++) {
the variable i having the signed type int is implicitly converted to the unsigned type size_t due to the usual arithmetic conversions because the expression sizeof(array) / sizeof(int) has the unsigned integer type size_t and the rank of the type size_t (that is usually an alias for the type unsigned long) is greater than the rank of the type int.
As a result the expression ( size_t )-1 (the variable i is set initially to -1) that is the left operand of the condition
i < sizeof(array) / sizeof(int) becomes a very big unsigned value due to propagating the sign bit.
Try for example this call of printf
printf( "( size_t )-1 = %zu\n", ( size_t )-1 );
So the condition of the if statement evaluates to logical false.
You could write for example
for ( i = -1; i < ( int )( sizeof(array) / sizeof(int) ); i++) {
to get the expected result - to execute the for loop.
Though in any case the loop will invoke undefined behavior because when i will be equal to ( int )( sizeof(array) / sizeof(int) ) - 1 the expression array[i+1] will try to access memory beyond the defined array.
It will be much better and correct to write
for ( size_t i = 0; i < sizeof(array) / sizeof(*array); i++) {
printf("%d ", array[i]);
}
-1? I think, it's a negative value being casted tosize_t.-Wsign-compareworks for me, but-Walldoesn't :/isuch that-1 <= i < 4(in mathematical sense, not C sense). How many are those? My hand says {-1, 0, 1, 2, 3} makes 5 in total. Why do you expect 4 numbers to be printed?