0

# Increment and decrement

If a=10 so if we write ++a it gives 11 but by mathematical way it gives 20

11th Sep 2020, 4:49 PM
Harsh Singh + 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=apphttps://code.sololearn.com/chPAcDs7YZgV/?ref=apphttps://code.sololearn.com/cm4wSfJZ8h28/?ref=app
11th Sep 2020, 5:50 PM
Danijel Ivanović + 4
In programming it just increases the value by 1.
11th Sep 2020, 4:59 PM
D_Stark + 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
11th Sep 2020, 5:00 PM
Феникс 