评估顺序 >> 和 [++]
Order of evaluation >> and [++]
我对 C++ 中运算的优先级有疑问。我在 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
中搜索优先级
我没有得到任何明确的结论。如果我这样做
var >> array[n++];
运算符 >> 用于读取字符的流。 ¿我阅读的内容存储在哪里?在 n 还是在 n+1?
谢谢
存储在n中。 n++ 递增计数器和 returns 旧值。 ++n 递增计数器和 returns 新值。
另见What is the difference between ++i and i++?
这实际上与优先级无关,与 post-增量的语义有关。
var >> array[n++];
n++
将递增 n
并评估为 n
的原始值。因此,它相当于写作:
var >> array[n];
++n;
因此该值将被读入array[n]
。
我对 C++ 中运算的优先级有疑问。我在 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
中搜索优先级我没有得到任何明确的结论。如果我这样做
var >> array[n++];
运算符 >> 用于读取字符的流。 ¿我阅读的内容存储在哪里?在 n 还是在 n+1?
谢谢
存储在n中。 n++ 递增计数器和 returns 旧值。 ++n 递增计数器和 returns 新值。
另见What is the difference between ++i and i++?
这实际上与优先级无关,与 post-增量的语义有关。
var >> array[n++];
n++
将递增 n
并评估为 n
的原始值。因此,它相当于写作:
var >> array[n];
++n;
因此该值将被读入array[n]
。