+ 5

What does ++3 or i++ mean in cpp?

7th Jun 2018, 7:35 AM
Deesha Devi Raghu
Deesha Devi Raghu - avatar
4 Antworten
+ 6
Unary prefix increment operator e.g. ++x Unary postfix increment operator e.g. x++ Unary prefix decrement operator e.g. --x Unray postfix decrement operator e.g. x-- These are simple operations that usually being used for manipulating the loop counter variable by one and NOT constant values as ++3 or alike. Simply put, these handy operators are shorthand for statements like: x = x + 1 --> ++x or x++ x = x - 1 --> --x or x-- The only important difference regarding prefix and postfix schemes is, the precedence by which the result of the operation being evaluated. For example, In the following postfix scheme, while loop cycles through its body 3 times, since x's current value is participated in while loop condition evaluation and then decrement by one, int x = 3; while (x--) { // body } But, in prefix scheme, prefix operator does its effect on x first, and then x is going to being evaluated, so in the following snippet, the body experience just 2 repetitions. int x = 3; while (--x) { // body }
7th Jun 2018, 8:36 AM
Babak
Babak - avatar
+ 4
this is post increment and pre increment operator. ++i means compiler increments by one and then uses it in the operation i++ means uses the value I in the operation and then increments it https://code.sololearn.com/c6xXOsUeHID9/?ref=app
7th Jun 2018, 8:05 AM
Suhail Ahmad
Suhail Ahmad - avatar
+ 2
increments. it increases the number
7th Jun 2018, 8:00 AM
Fabio Rocha
Fabio Rocha - avatar