0

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

Community
  • 1
  • 1
acostela
  • 2,597
  • 3
  • 33
  • 50
  • Order of evaluation and precedence are completely different concepts, neither one relevant to your question. – molbdnilo Dec 15 '15 at 10:10

2 Answers2

8

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].

TartanLlama
  • 63,752
  • 13
  • 157
  • 193
  • Or ... *the value will be read into **array[n-1]** if you take n to be the after-the-statement value* – Nawaz Dec 15 '15 at 10:11
4

It is stored in n. n++ increments the counter and returns the old value. ++n increments the counter and returns the new value.

Also see What is the difference between ++i and i++?

Community
  • 1
  • 1
Houbie
  • 1,406
  • 1
  • 13
  • 25