0

How i understand ++x,x++ these operations in c++

i want learn theoey.any expert?

15th May 2018, 1:31 AM
Oshada Basnayake
Oshada Basnayake - avatar
5 Réponses
+ 4
let me just try If i = ++x means pre increment operator ( means x+1 ) .In this case , x is first incremented while x++ is known as post incremented operator and if i = x++ than it means first I assigns with x and than x is incremented by 1 eg. x=y=6 i=x++ than value of i=6 as it is assigned with x first but value of x = 7 as after assigning x is increased by 1 if i = ++x than value of both i and x will be 7 as they increased first hope u will understand 😊😊
15th May 2018, 3:30 AM
Priyanka Thakur
Priyanka Thakur - avatar
+ 1
thanks all
16th May 2018, 3:52 AM
Oshada Basnayake
Oshada Basnayake - avatar
0
Hi, using C++ ------------------- Prefix Expression :- ++var // example:- ++a Postfix Expression :- var++ // example:- a++ examples:- //for postfix only #include <iostream> using namespace std; int main(){ int c = 10; cout << c++ << endl ; // [ postfix Var 'c' , cout does not print the increment value // it is printed on next line, ( mostly used for loops ) ] cout << c; // incremented value is printed here} ------------------- //for prefix only #include <iostream> using namespace std; int main(){ int c = 10; cout << ++c << endl ; // [ Prefix Var 'c' , cout prints the incremented value here ] } ------ // prefix and postfix increments the variable value by [ +1 ] only. So, postfix variable is incremented and kept somewhere inside memory of the computer as a pointer , and then it is printed . but prefix variable is incremented and printed on same line ----------------- refer to this:- https://www.programiz.com/article/increment-decrement-operator-difference-prefix-postfix
15th May 2018, 2:40 AM
Rajeeb
0
hi, actually you are assigning the value of x++ to variable i so, when you are cout << on screen with variable i . var i gets printed on screen with incremented value.
15th May 2018, 3:42 AM
Rajeeb