The program is as
main()
{
int a=1;
if( a-- > 0)
printf("AAAA");
else
printf("BBBB");
}
Its output is AAAA
and if I use
main()
{
int a=1;
if( (a--) > 0)
printf("AAAA");
else
printf("BBBB");
}
then why again the output is AAAA
.
()
has more preference then --
.
The postfix operator --
has higher precedence than any boolean comparison operator.
What do you expect exactly? a--
always evaluates to the value of a
which is decremented after evaluation.
The postfix --
operator returns the original value of the variable, even after decrementing it.
So yes, a
is decremented before the comparison, but the result of the expression a--
is not a
, but the value 1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With