Commas & parentheses magic | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

Commas & parentheses magic

Just look for this code: https://code.sololearn.com/c3hQ2573ECgC/?ref=app And try to explain: what happens when we using commas and parentheses in both assing expressions? Can you give please some links to sources where could be founded more about nonstandard syntax definitions in c++ (I mean other magic c; )

14th Jul 2018, 3:34 PM
Rull Deef 🐺
Rull Deef 🐺 - avatar
8 Answers
+ 10
I'm not sure what you mean by non-standard. That code is standard C++. The results are fully based on operator precedence. The parentheses happen first with the last expression (3) being returned from it. a = (1, 2, 3); The assignment happens first (a=1) then the others occur. a = 1, 2, 3;
14th Jul 2018, 4:03 PM
John Wells
John Wells - avatar
+ 7
I still not sure why your talking about stack as nothing in that expression uses the stack except the a variable. Because of the parentheses, the statement is processed as if it was coded: 1, 2, a = (3); The values 1 & 2 aren't used so they vanish. Of course, if it was coded with a function that had side effects, the effects would still occur, but the return value is ignored.
16th Jul 2018, 1:01 AM
John Wells
John Wells - avatar
+ 6
Thanks, but by 'nonstandard' I mean 'mostly unknown' or unusual and interesting syntax of c++
14th Jul 2018, 4:06 PM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 6
Your second statement is the same as: int a = 1, b = 2, c, d = 3; The other one isn't really used. In fact, try as hard as I can, I can't think of a reason I'd ever use it.
14th Jul 2018, 4:19 PM
John Wells
John Wells - avatar
+ 6
Okay, thanks ;)
14th Jul 2018, 4:22 PM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 3
Daniel Bandeira I don't understand your question.
15th Jul 2018, 9:20 PM
John Wells
John Wells - avatar
0
"stack Reading "of information at the first case, right ?
15th Jul 2018, 9:03 PM
Daniel Bandeira
Daniel Bandeira - avatar
0
I've corrected my sentence. and now?
15th Jul 2018, 11:29 PM
Daniel Bandeira
Daniel Bandeira - avatar