0

Whats the difference between x=++4 and x=+4 and x=4++

just confused about the double operators

13th Dec 2016, 6:41 PM
Pirashanth
5 Answers
+ 3
all of those are errors... what you probably meant : x++ increment x but returns the old value ++x increment x but returns the new value x += 4 adds 4 to x (notice its +=, not =+ like you wrote)
13th Dec 2016, 6:49 PM
Udi Finkelstein
Udi Finkelstein - avatar
+ 2
just to make it clear : you cannot use ++ on constants, only on variables (and if we talk about c++ here , then these variables must never be const)
13th Dec 2016, 7:04 PM
Udi Finkelstein
Udi Finkelstein - avatar
+ 2
example: cout << a[x++] ; // print values indexed by x and increment x to next element of a
13th Dec 2016, 7:10 PM
Udi Finkelstein
Udi Finkelstein - avatar
0
thank you :D
13th Dec 2016, 7:01 PM
Pirashanth
0
x++ increments but returns the old value, so what's the point of that? in the code does it use the incremented value?
13th Dec 2016, 7:07 PM
Pirashanth