question d in my book: i, j, k are int variables
i = 3; j = 4; k = 5;
printf ("%d", i % j + i < k) ;
The program output is 0. However, the expression is left associative, and when I do it in my head, I think that 3 % 4 is 0, then 0 + 3 is 3, and lastly, 3 is < 5,
so, since 3 < 5, then i < k, which means it's a true statement and the output should therefore be 1 (true), and not 0 (false)
What am I getting wrong when I think it through?
I wrote:
i = 3; j = 4; k = 5;
printf ("%d", i % j + i < k) ;
The program output is 0. However, the expression is left associative, and when I do it in my head, I think that 3 % 4 is 0, then 0 + 3 is 3, and lastly, 3 is < 5,
so, since 3 < 5, then i < k, which means it's a true statement and the output should therefore be 1 (true), and not 0 (false)
What am I getting wrong when I think it through?
I wrote:
Code:
#include <stdio.h>
main ()
{
int i, j, k ;
i = 3 ;
j = 4 ;
k = 5 ;
printf ("%d\n", i % j + i < k) ;
return 0 ;
}