0
if(sizeof(int)>-1)
{
printf("0");
}
else
{
printf("else");
}

it executes the else statement. Why doesnt it follow the if part even if int size>-1.

1 Answers1

2

sizoe(int) yields an integer of type size_t which is unsigned integer. Due to usual arithmetic conversions in C, -1 gets converted into a size_t and a hence, -1 becomes SIZE_MAX. Obviously sizeof(int) is less than SIZE_MAX and the condition (if) is false.

P.P
  • 117,907
  • 20
  • 175
  • 238