Hi Folks,
This question may well have been asked and answered before. But, sorry
that I couldn't find one from the archives.
I typed up this program and compiled it with gcc 3.3.2
main() {
int i = -3,j= 2,k=0,m;
m = ++i || ++j && ++k;
printf("\n%d %d %d %d\n",i,j,k,m);
}
and got the output to be
-2 2 0 1
I presumed that the answer should have well been
-3 3 1 1
as ++j and ++k would first be evaluated and && operator applied to
obtain the result to be TRUE (3 && 1). Hence, ++i wouldn't be evaluated
as one part of || goes TRUE.
The ANSI C specification clearly states that && has precedence over ||.
Could someone explain why this strange "-2 2 0 1" output for the program
is obtained?
Cheers
Vivek