+ 1
hello. please help me to understand this code: int main(){ int i=50, b=20,c=30; i=c,b; cout<<i<<endl; i=(c,b); cout<<i<<endl; } outputs: 30 20 I don't realize, what does the parantheses change (3 and 5 line)
3 Antworten
+ 1
it's related to , operator.
when u assign any value to variable with , operator it will take 1st value but the parentheses have more precedence than coma so complier read () from left to right and assign last value to variable
0
Not bad code -_-
How I know, if there are parantheses, variable takes last element in parantheses, else it takes first element. I haven't see such code anywhere, but I think it is caused by compiler(It wants to read to final in parantheses).
0
Ehm pls never ever write code like this. I've never seen this in my entire life and I have seen bad code...
Why is it bad? It does not fulfill a purpose that cannot be expressed in an easier, much more readable way.