Help ! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Help !

Void main() { Int x=5,y=3; Int s=0; S+=(x++)+y*(y++)+x+(++y); Cout<<s; } Why the output is 27

1st Jan 2018, 8:33 AM
Dipankar Verma
Dipankar Verma - avatar
9 Answers
+ 17
👉👉U must see the precedence table for operators used in c++ to see which operator have more precdence & will execute first 👈👈 /*for solving all these types of questions based on precedence order , use the order & solve it*/
1st Jan 2018, 8:58 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 6
first there is a syntax error plz replace Void Int S and Cout with void int s and cout because c++ is a case sensitive language and second don't do ++y and y++ in a single line this will cause unexpected result because precedence of ++y and y++ is same then it depends on compiler that compiler may calculate ++y first or y++ first in both the cases answer is different
1st Jan 2018, 8:53 AM
Randeep Singh
Randeep Singh - avatar
+ 6
Charan bro x++ is post increment operator so it gives x= 5 not 6 in expression
1st Jan 2018, 8:59 AM
Randeep Singh
Randeep Singh - avatar
+ 3
27
1st Jan 2018, 8:39 AM
ASHOK KUMAR K
ASHOK KUMAR K - avatar
+ 3
Hmm Thank you
1st Jan 2018, 9:05 AM
Dipankar Verma
Dipankar Verma - avatar
+ 3
I also clear with assignment operations
1st Jan 2018, 9:21 AM
ASHOK KUMAR K
ASHOK KUMAR K - avatar
+ 2
multiply
1st Jan 2018, 8:48 AM
ASHOK KUMAR K
ASHOK KUMAR K - avatar
+ 1
What about the * sign
1st Jan 2018, 8:45 AM
Dipankar Verma
Dipankar Verma - avatar
+ 1
yes you are right
1st Jan 2018, 8:54 AM
ASHOK KUMAR K
ASHOK KUMAR K - avatar