+ 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; )
8 Respuestas
+ 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;
+ 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.
+ 6
Thanks, but by 'nonstandard' I mean 'mostly unknown' or unusual and interesting syntax of c++
+ 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.
+ 6
Okay, thanks ;)
+ 3
Daniel Bandeira I don't understand your question.
0
"stack Reading "of information at the first case, right ?
0
I've corrected my sentence. and now?