#include<stdio.h>
void main()
{
int a=2;
if ((sizeof(a))>-1)
printf("a");
else
printf("b");
}
Why is the program giving output as b
When sizeof(a) = 4, which is greater than (-1)
#include<stdio.h>
void main()
{
int a=2;
if ((sizeof(a))>-1)
printf("a");
else
printf("b");
}
Why is the program giving output as b
When sizeof(a) = 4, which is greater than (-1)
sizeof
returns size_t
(which is implementation defined unsigned integer type).
So -1
gets converted to unsigned too. Assuming two's complement representation of negative integers, (unsigned)-1
is greater than (unsigned)4
, hence the output is b
.