M
marko
/* code start */
int a = 0;
/* expected evaluation and excution order with precedence in mind
/* False(3) , True(1), False(2) */
if ( (a=1) == 0 || 0 != 1 && (a =2) == 1)
putchar('T');
printf("%d", a);
/* code end */
2
"c:\src\test\lcc\test.exe"
Return code 0
Execution time 0.001 seconds
Press any key to continue...
The result shows, code skipped "(a=1) == 0" and expression is false
/* code start */
int a = 0;
/* False(3) , True(1), False(2) */
if ( (a=1) == 0 || 0 != 1 && a == 1)
putchar('T');
printf("%d", a);
/* code end */
T1
"c:\src\test\lcc\test.exe"
Return code 0
Execution time 0.051 seconds
Press any key to continue...
Result shows variable a has been changed as expected though excuted
putchar('T'); statement unexpectedly
logical operator && has higher precedence though both &&, || associates left
to right
so how does evaluation order goes in this code?
feel free to edit comments above in the code to demonstrate execution
order(like number next to True or False)
int a = 0;
/* expected evaluation and excution order with precedence in mind
/* False(3) , True(1), False(2) */
if ( (a=1) == 0 || 0 != 1 && (a =2) == 1)
putchar('T');
printf("%d", a);
/* code end */
2
"c:\src\test\lcc\test.exe"
Return code 0
Execution time 0.001 seconds
Press any key to continue...
The result shows, code skipped "(a=1) == 0" and expression is false
/* code start */
int a = 0;
/* False(3) , True(1), False(2) */
if ( (a=1) == 0 || 0 != 1 && a == 1)
putchar('T');
printf("%d", a);
/* code end */
T1
"c:\src\test\lcc\test.exe"
Return code 0
Execution time 0.051 seconds
Press any key to continue...
Result shows variable a has been changed as expected though excuted
putchar('T'); statement unexpectedly
logical operator && has higher precedence though both &&, || associates left
to right
so how does evaluation order goes in this code?
feel free to edit comments above in the code to demonstrate execution
order(like number next to True or False)