Why does the below code print 2 ? https://code.sololearn.com/cKO3S0e9aj57/?ref=app
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*
Thanks...absolutely you cleared everything🙏
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?
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.
Ohkay got it👍...thanks😁
Gauri Shirkande your welcome 🙃🙂.