0
Increment and decrement
If a=10 so if we write ++a it gives 11 but by mathematical way it gives 20
3 Answers
+ 8
The increment and decrement operators (++, --) increment and decrement numeric types by 1.
The operator can either precede or follow the variable, depending on whether you want the variable to be updated 'before' or 'after' the expression is evaluated.
• The prefix: increments the value of x,
and then assigns it to y.
int x = 5;
int y = ++x; // x is 6, y is 6
• The postfix: assigns the value of x to y,
and then increments x.
int x = 5;
int y = x++; // x is 6, y is 5
• https://www.sololearn.com/post/150404/?ref=app
• https://code.sololearn.com/chPAcDs7YZgV/?ref=app
• https://code.sololearn.com/cm4wSfJZ8h28/?ref=app
+ 4
In programming it just increases the value by 1.
+ 1
Hi!
a++ stands for a = a + 1
a = 10
a++ --> 10 + 1 --> 11
To have the result of 20 you should have:
a = 10
a += a --> a = a + a --> 20
https://www.programiz.com/article/increment-decrement-operator-difference-prefix-postfix
https://en.m.wikipedia.org/wiki/Increment_and_decrement_operators
Hot today
Тренажер кода
0 Votes
Why is my answer only coming out right for one test case even when I use the recommended one
0 Votes
Python palindrome challenge.
1 Votes
Java
0 Votes
Pls what's wrong?
0 Votes
help my code does not iterate
0 Votes