+ 1
What does ++ , -- mean in programming language C++
C++
9 Antworten
+ 15
++ is the increment operator. It increment of 1 the variable.
x++; is equivalent to x = x + 1; or to x += 1;
The increment operator can be written before (pre - increment) or after the variable (post-increment).
In case of a statement with only the increment operator, there is no difference among pre and post:
x++; is equivalent to ++x;
But in more complex statements there is difference:
y = x++; is NOT equivalent to y = ++x;
y = ++x; is equivalent to the following 2 statements:
x = x +1;
y = x;
y = x++; instead is equivalent to the 2 statements:
y = x;
x = x + 1;
The 2 statements are the same, but they are executed in opposite order (the value of x is the same, while the value of y is different).
The same apply for decrement operator --.
+ 2
-- decrement
++increment
int x=6,y;
y=x++;
\\output x=7;y=6;
y=++x;
\\output x=7; y=7;
the same applies to the decrementation..
+ 1
++ and -- are the short hands of +1 and -1 respectively. for example x=x+1/x+=1 or x=x-1/x-=1 instead we could write as x++ and x-- respectively
+ 1
--=Decrement
++=Increment
r-- means r=r-1
r++ means r=r+1
+ 1
Increment is ++
Decrement is --
There is also prefix and post fix
Prefix increment ++x
Prefix decrement --x
Postfix increment x++
Postfix decrement x--
In prefix, the value is increased or decreases before performing an operation.
In postfix, the operation is performed with the initial value before the decrement or increment
Example
Int X= 5;
Int Y= ++X;
System.out.println(y);
}
//output is 6
Example
Int x = 5;
Int y = x++;
System.out.println(y);
}
//output is 5
0
ok
0
Pre-increment:++X
Post-increment:X++
Pre-decrement:--X
Post-decrement:X--
0
Hi