Behaviour of && in C programming language
I am beginner in C programming language, recently I have read about
Logical AND && operator.
NON-ZER0 && NON-ZERO = 1
NON-ZER0 && ZERO = 0
ZER0 && NON-ZERO = 0
ZER0 && ZERO = 0
But when I am dealing with the following program then I am not getting
expected answer.
int main(){
int x,y,z;
x = y = z = -1;
y = ++x && ++y && ++z;
printf("x = %d, y = %d, z = %d, x,y,z);
return 0;
}
I am expecting answer as
x = 0, y = 0, z = 0
but the answer is
x = 0, y = 0, z = -1
can anyone please explain, why I am getting this answer.
No comments:
Post a Comment