__shivam_kumar's blog

By __shivam_kumar, history, 3 years ago, In English

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++
Tags c++
  • Vote: I like it
  • -21
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Why is it so? What error can it cause?

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    It is not possible to post-increment an r-value.

    The value obtained by applying a postfix ++ is the value that the operand had before applying the operator. The operand shall be a modifiable lvalue. The result is an rvalue.
    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks, just googled what r-value and l-value are? We cannot increment a++. Thanks!