+ 6
Difference between ++x, x++
8 Respostas
+ 18
The increment operator has two forms, prefix (++x) and postfix (x++).
Prefix increments the value, and then proceeds with the expression.
Postfix evaluates the expression and then performs the incrementing.
as an example,
int pre, post, x, y;
pre = 10;
post = 10;
x = ++pre; //x is 11
y = post++; //y is 10
+ 3
++x is pre-increment, it will work before the execution of the statement.
for example:
int a=1;
cout<<++a;
it will give output 2.
while x++ is post-increment it will work after the execution of the statement.
for example:
int a=1;
cout<<a++;
it will give output 1.
still hv doubt then feel free to tell.
+ 1
y value is 11
+ 1
Execute the below program,
int x=10;
//Pre increment
z=++x; // Value of z will be 11
//Post Incrememt
z=x++;// Value of z will be 11 itself
+ 1
++x is prefix incrementit increases the value first then assigns it.
x++ is postfix increment,it assigns the value first then increases the value
0
post increment value can not be increment
0
because of first increment and after value is appear...
0
++x ll first increment n assign the value..while x++ ll assign n increment the value of x.x=10 & x++ value is 10 & ++x value is 11