+ 1

is it because of garbage value?

https://code.sololearn.com/caN0CU5hYxBY/#c

12th Sep 2020, 3:50 PM
tesla
tesla - avatar
5 Answers
+ 4
The C standard does not define what order the arguments will be evaluated. So when one of the arguments reassigns a value that is used in another argument, then the result may vary. When I ran it, the result (0 50 0) implied that the arguments were evaluated right-to-left. A different order of evaluation would give a different result. Do not write code like this!
12th Sep 2020, 4:13 PM
Brian
Brian - avatar
+ 2
No its not garbage .1 50 1 will be the Output of your code
12th Sep 2020, 4:02 PM
AS Raghuvanshi
AS Raghuvanshi - avatar
+ 2
Jayakrishna🇮🇳 but am confused i think Output should be 1 50 1 here Values will store in stack formate so first x==35 this will store means left to right .
12th Sep 2020, 4:42 PM
AS Raghuvanshi
AS Raghuvanshi - avatar
+ 1
😅🐍🐍😆 There happening first k>40, k=50, k==35, right to left.... so output 0 50 0 In the stack it store tokens by "top to bottom" but evaluation is depends on precedence of Operators. Generally expression evaluation is left to right (in equal precedence) , but In a function call in C, the order in which the argument expressions are processed is not defined. And printf is a function also, in which is sequenced first for evaluation is depends on compiler specifications.... So different compiler result different values.... In c/c++, you can encounter this undefined behaviour... Check out these.... May help.... https://en.m.wikipedia.org/wiki/Sequence_point https://gateoverflow.in/62411/undefined-behaviour-in-c
12th Sep 2020, 5:09 PM
Jayakrishna 🇮🇳
0
Your code has sequence point issue.. You may get different result in different compilers.. depending on left to right, or right to left evaluation. So it may 0 50 0 or 1 50 1 Not garbage value.
12th Sep 2020, 4:37 PM
Jayakrishna 🇮🇳