Can somebody please explain output of below code-
int a =-3;
printf("%d",!a);
The output is 0.
I cannot understand why i get output as 0.
Can somebody please explain output of below code-
int a =-3;
printf("%d",!a);
The output is 0.
I cannot understand why i get output as 0.
Quoting C11, chapter 6.5.3.3
The result of the logical negation operator
!is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0. The result has typeint. The expression!Eis equivalent to(0==E).
In your case, it can be seen as
printf("%d", (a == 0)); // where a is -3
which evaluates to a falsy result, thereby printing 0 as the result.