Assignment and increment | SoloLearn: Learn to code for FREE!


Assignment and increment

Explain Why following code alerts 5 and not 6. I know it applies assignment first and increment next.

11/29/2018 2:49:42 AM

Sindhe Kishan

4 Answers

New Answer


+4 Here it is nicely explained


var x=5; x= x++; //x++ does not increment because the value here is: 5


In the post he said x++ evaluates to x and hence old value is assigned to x. But after assignment increment operator should execute and increase the value of x by 1 right?