下面的代码片段来自 Herb Sutter 的博客
g++ 输出10
。MSVC 也可以输出10
。不同编译器的输出可能不同。
我不明白变量i
是如何增加的。谁能解释一下输出是怎么来的10
,输出10
真的正确吗?
#include <iostream>
#include <vector>
#include <string>
int main()
{
std::vector<int> v = { 0, 0 };
int i = 0;
v[i++] = i++;
std::cout << v[0] << v[1] << std::endl;
}