0
int main(void)
    {
       int array[] = {1,2,3,4,5,6,7};
       int i = -1;
       if(i <= (sizeof(array)/sizeof(array[0])) -2)
           printf("a\n");
       else
           printf("b\n");
       return(0);    
    }

I don't know why the IF expression is false.

haccks
  • 104,019
  • 25
  • 176
  • 264
caramel
  • 13
  • 1

1 Answers1

0

You are trying to compare a signed integer int and an unsigned integer size_t. Following C integer promotion rules, i gets promoted to an unsigned integer and therefore wraps to a very large number. When you compare that to the small value on the right side, the result is false.

2501
  • 25,460
  • 4
  • 47
  • 87