+ 2
About printing
Why does the below code print 2 ? https://code.sololearn.com/cKO3S0e9aj57/?ref=app
6 Respostas
+ 4
As assignment operation is of higher precedence than that of "," thus first *x* is assigned the value 2 then rest of them were read.
If you use parentheses"()" to enclose the stuff in brackets like this:-
x = (2,3,4,5);
Then everything inside the parentheses will execute first(because of higher precedence of parentheses), so the program will go through all the valus and will assign last value(5 in this case) to *x*
+ 2
Thanks...absolutely you cleared everything🙏
+ 2
One more question I have in this case is when you declare and define simultaneously i.e
int x = 2,3,4,5;
It throws error while printing x. What's the reason?
+ 2
Gauri Shirkande , this is an interesting one.
Here your program is assuming that you are trying to declare another variable of int type but using a constant("3" in this case) as the name thus it is giving out this error.
+ 2
Ohkay got it👍...thanks😁
+ 1
Gauri Shirkande your welcome 🙃🙂.