Skip to content

C++ Increment and Decrement Operators #6805

@JankieQwQ

Description

@JankieQwQ

In some Chinese C++ textbooks (For example: Tan Haoqiang C programming), there are often exercises like the following:

#include <iostream>

int main(){
    int i = 1;
    std::cout << (i++)+(++i) << endl;
}

The textbook provides the answer as 6, but when compiled with G++, the output is 4 or 5 or 6(Depends on level of optimization).

I want to have some specification for this operation, such as:In the same row, if the variable has been increment more than once, the value before the first increment of the variable is used as the reference value.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions