Int main() int a=5 Int b=++a*a++ Print(%d,b) | Sololearn: Learn to code for FREE!

0

# Int main() int a=5 Int b=++a*a++ Print(%d,b)

please explain how output is 42.ignore syntax errors.

6/6/2017 3:34:56 PM

Nitish Kulkarni

+1

(++a = 6) * (a++ = 7) = 42

0

@scott i understand how ++a is 6 but a++ should be 6 as well because a++ evaluates first then it increments.so i think answer should be 36=6*6

0

i agree how ++a is 6 but a++ evaluate first then its increments so i think a++ is 6.so answwr will be 36.can u explain how a++ is 7.?

0

@Nitish, i had an answer for you before i saw you had a c++ tag for this. I don't know if you know this is a JavaScript q&a.

0

My new answer is if this was c++ your answer 36 would probably be correct. If JavaScript, then it's syntactically written incorrectly so it would (and did) console.log() to 36.

0

but in c++ i got answer 42 not 36

0

++a=6..it will Increment the value of a=5...then a++=7..because this will increment the value of a..which was incremented before(a=6)

0

a++ will be 6 because it will execute first then incremental like if i=5 j=i++ then i=6 and j=5