Search code examples
c++operator-precedence

Order of evaluation >> and [++]


I have a question about the precedence in an operation in C++. I have search for precedence in http://en.cppreference.com/w/cpp/language/operator_precedence and I read this question that is more or less the same array increment difference in C

I didn't get any clear conclusion. If I do

var >> array[n++];

Operator >> is for stream that is reading chars. ¿Where it is stored what I read? In n or in n+1?

Thank you


Solution

  • This isn't really to do with precedence, it's to do with the semantics of post-increment.

    var >> array[n++];
    

    n++ will increment n and evaluate to the original value of n. As such, it's equivalent to writing:

    var >> array[n];
    ++n;
    

    So the value will be read into array[n].