you cannot do nesting of post-increment operator whereas pre-increment nesting does not cause any problem
conclusion : never do post increment nesting
eg :
int a = 10; cout<<(++(++a))<<"\n";// valid in c++ cout<<((a++)++); // in-valid in c++
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
you cannot do nesting of post-increment operator whereas pre-increment nesting does not cause any problem
conclusion : never do post increment nesting
eg :
int a = 10; cout<<(++(++a))<<"\n";// valid in c++ cout<<((a++)++); // in-valid in c++
Название |
---|
Why is it so? What error can it cause?
It is not possible to post-increment an r-value.
Thanks, just googled what r-value and l-value are? We cannot increment a++. Thanks!
I encountered this error in Java while trying to nest pre- and post-increment operators and came across this thread while trying to find the reason. I want to add that nesting of both pre-increment and post-increment operators is not allowed in Java. E.g. ~~~~~ int a = 5; System.out.println(++(++a)); // required: variable found: value System.out.println((a++)++); // required: variable found: value ~~~~~
Reference — 1. Postfix Expressions — https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.14 2. Prefix Expressions — https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.15.1