Not operator and unary logical operator in c/c++

main()
{
int a=20;
a=!a>14;
printf(“a=%d”,a);
}
Tutorial answer:a=0

Debugging solution:
In these equation
a=!>14;
!(Not)operator has the higer priority compare to >
So unary logical operator ! execute first.
!a=!20=0(if the value is greater than one mean result is one. if the value is less than 0 mean value is 1)0>14(it is false)so there result is zero.so answer is 0;

Post a Comment

0 Comments