I don't know why the sizeof
operator is not evaluated in a for loop condition at run time. I am trying this simple code with different C compilers but it always print nothing. But if I replace sizeof(i)
with 4
then it works fine:
for(int i = -2; i <= 4; i++)
#include <stdio.h>
int main()
{
for(int i = -2; i <= sizeof(i); i++)
printf("Hello World");
return 0;
}
size_t
is greater than or equal to the rank ofint
, otherwise the code will work as both values will be converted intoint
. It's the "usual arithmetic conversions" rather than the "arithmetic promotion rules" which may be confused for "integer promotions". – Eggshell