I'm struggling to understand the behavior of the below code:
#include <stdio.h>
int main(void)
{
int i;
int j;
int k;
i = 7;
j = 8;
k = 9;
printf("%d\n", (i = j) || (j = k));
printf("%d, %d, %d\n", i, j, k);
return (0);
}
Output:
1
8, 8, 9
Question:
I understand that expr1 | | expr2 has the value 1 if either expr1 or expr2(or both)has a nonzero value.
The value of
i
increased from7
to8
becausej
's value is assigned toi
but the same way why does the value of thej
is not increased even thoughj = k?
I was expecting an
output
1
8, 9, 9