+ 8

What is the differance between --x and x--?

challenges made me confused between them .

28th Apr 2017, 5:37 PM
Enas Emad
Enas Emad - avatar
19 ответов
+ 3
--x has "-- " preceding x which means whenever code runs and it is going to work on x then it will first decrease x by1 and then use it . but in case of x-- the code will first use the current value of x once and then decrease it with on it would not decrease x till its current value is used once 😉hope u got it .......
29th Apr 2017, 6:50 AM
Dgionbxeeruonb Hkkvnjf
Dgionbxeeruonb Hkkvnjf - avatar
+ 14
Yep, you got it! int x = 3; cout << --x; // outputs 2 int y = 3; cout << y--; // outputs 3, then decrements y cout << y; // so this outputs 2 now.
28th Apr 2017, 5:50 PM
Tashi N
Tashi N - avatar
+ 11
--x decrements the value first and uses the new value in the statement. x-- first executes the statement and decrements the value of x after that.
28th Apr 2017, 5:40 PM
Tashi N
Tashi N - avatar
+ 11
You're welcome ^^
28th Apr 2017, 5:52 PM
Tashi N
Tashi N - avatar
+ 8
yeah , I got it . thanks @tashi N 😀
28th Apr 2017, 5:52 PM
Enas Emad
Enas Emad - avatar
+ 7
so , in --x the new value will be excuted . However x-- the value won't be excuted in the statement . right?
28th Apr 2017, 5:45 PM
Enas Emad
Enas Emad - avatar
+ 5
good explanation . now I completely can differentiate between them, thank you @Nitish Rawat :)
29th Apr 2017, 11:43 AM
Enas Emad
Enas Emad - avatar
+ 3
did you change your name .. I thought your name is Nitish
29th Apr 2017, 11:48 AM
Enas Emad
Enas Emad - avatar
+ 3
good brother ..😃
29th Apr 2017, 11:51 AM
Enas Emad
Enas Emad - avatar
+ 3
I am now in college.
29th Apr 2017, 11:53 AM
Enas Emad
Enas Emad - avatar
+ 3
I hope you have nice time in studying
29th Apr 2017, 11:55 AM
Enas Emad
Enas Emad - avatar
+ 3
engineering .but how did you know?
29th Apr 2017, 11:56 AM
Enas Emad
Enas Emad - avatar
+ 2
welcome enas 😊
29th Apr 2017, 11:44 AM
Dgionbxeeruonb Hkkvnjf
Dgionbxeeruonb Hkkvnjf - avatar
+ 1
actually 😂it is abhishek my younger brother changed it for fun ...
29th Apr 2017, 11:50 AM
Dgionbxeeruonb Hkkvnjf
Dgionbxeeruonb Hkkvnjf - avatar
+ 1
its easy to guess . u r in college 1yr . in India first year engineering syllabus has c++
29th Apr 2017, 11:57 AM
Dgionbxeeruonb Hkkvnjf
Dgionbxeeruonb Hkkvnjf - avatar
+ 1
I meant than not only in India but mostly everywhere first year engineering has c++ by the way good luck ...
29th Apr 2017, 12:07 PM
Dgionbxeeruonb Hkkvnjf
Dgionbxeeruonb Hkkvnjf - avatar
+ 1
for ur engineering dear
29th Apr 2017, 12:07 PM
Dgionbxeeruonb Hkkvnjf
Dgionbxeeruonb Hkkvnjf - avatar
0
same here
29th Apr 2017, 11:55 AM
Dgionbxeeruonb Hkkvnjf
Dgionbxeeruonb Hkkvnjf - avatar
0
engineering or bsc in computer sciences?
29th Apr 2017, 11:55 AM
Dgionbxeeruonb Hkkvnjf
Dgionbxeeruonb Hkkvnjf - avatar