New thing about sololearn compiler | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

New thing about sololearn compiler

It does not add 1 in variable if you write statement like that x=x++ in c++.While visual studio does add 1. Cannot say about other compilers. I have not used them. Hahahhaha It wasted quite my time.

28th Aug 2017, 7:32 AM
Hassan Sajjad
Hassan Sajjad - avatar
8 Answers
+ 9
I know what you mean. its not a new thing, it has been around since forever.
28th Aug 2017, 7:51 AM
jay
jay - avatar
+ 9
yeah its the same as saying x=x then going back after you already got your answer and saying oh i mean x=x+1 but not changing the answer. The behaviour you see is actually quite logical when you think about it
28th Aug 2017, 7:57 AM
jay
jay - avatar
+ 8
well it shouldnt. visual studio is probably correcting your mistake for you if it really works there as you state. the reasoning behind this is as follows. postfix assigns a value after the code is evaluated. so when you state x = x++; the following happens. assign the value from a copy of x into x, after this assignment add one to the value in the temp copy of x. simply use x++; on its own both in visual studio and here and the behaviour will be as expected
28th Aug 2017, 7:44 AM
jay
jay - avatar
+ 7
must autocorrect it for you when its compiled
28th Aug 2017, 8:08 AM
jay
jay - avatar
+ 2
Ooky. I did not know that before. It surprised me a bit so I mentioned it.
28th Aug 2017, 7:53 AM
Hassan Sajjad
Hassan Sajjad - avatar
+ 2
If its logical here than its not logical in visual studio by the way
28th Aug 2017, 8:01 AM
Hassan Sajjad
Hassan Sajjad - avatar
+ 2
No, Beacuse now I know it
28th Aug 2017, 8:10 AM
Hassan Sajjad
Hassan Sajjad - avatar
+ 1
Bro I am stating that it does not increments here. The value remains same even in next line.Check it U will be amazed
28th Aug 2017, 7:46 AM
Hassan Sajjad
Hassan Sajjad - avatar