0

Why different results in c while using assignment operator in C

I am getting different results in the following code int main( ) { int k = 35 ; printf ( "\n%d %d", k == 35, k = 50) ; return 0; } It prints 0 50 int main( ) { int k = 35 ; printf ( "\n%d", k == 35) ; return 0; } While it prints 1 Why is it 0 in first case and 1 in second https://code.sololearn.com/cEXWmBmB5B2A/?ref=app

6th Feb 2020, 3:50 PM
Manish Singh
Manish Singh - avatar
1 Réponse
+ 2
You can not know in which order your function arguments will be evaluated - undefined behaviour. That's why we don't use AND change the same value in one statement. Seems k=50 is done first, so after that k==35 obviously would return false.
6th Feb 2020, 4:26 PM
HonFu
HonFu - avatar