0
How i understand ++x,x++ these operations in c++
i want learn theoey.any expert?
5 Respuestas
+ 4
This question's been already asked before.
Kindly refrain from creating duplicate posts.
https://www.sololearn.com/discuss/1030267/?ref=app
https://www.sololearn.com/discuss/160327/?ref=app
https://www.sololearn.com/discuss/208414/?ref=app
https://www.sololearn.com/discuss/305422/?ref=app
https://www.sololearn.com/discuss/98959/?ref=app
+ 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 😊😊
+ 1
thanks all
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
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.