What is i+++ increment in c++

前端 未结 3 1521
别跟我提以往
别跟我提以往 2021-01-01 06:19

can anyone tell me what is the process of i+++ increment in c++.

相关标签:
3条回答
  • 2021-01-01 06:33

    if you mean i++ then its incrementing the value of i once its value has been read. As an example:

    int i = 0;   // i == 0
    int j = i++; // j == 0, i == 1
    
    0 讨论(0)
  • 2021-01-01 06:40

    i+++; will not compile. There is no operator +++ in C++.

    i+++j, on the other hand, will compile. It will add i and j and then increment i. Because it is parsed as (i++)+j;

    0 讨论(0)
  • 2021-01-01 06:53

    It is a syntax error.

    Using the maximum munching rule i+++ is tokenized as:

    i ++ +
    

    The last + is a binary addition operator. But clearly it does not have two operands which results in parser error.

    EDIT:

    Question from the comment: Can we have i++++j ?

    It is tokenized as:

    i ++ ++ j
    

    which again is a syntax error as ++ is a unary operator.

    On similar lines i+++++j is tokenized by the scanner as:

    i++ ++ + j
    

    which is same as ((i++)++) + j which again in error as i++ is not a lvalue and using ++ on it is not allowed.

    0 讨论(0)
提交回复
热议问题