Index, assignment and increment in one statement behaves differently in C++ and C#. Why?

后端 未结 7 993
醉酒成梦
醉酒成梦 2021-01-18 16:34

Why is this example of code behaving differently in c++ and C#.

[C++ Example]

int arr[2];
int index = 0;
arr[index]         


        
7条回答
  •  死守一世寂寞
    2021-01-18 17:25

    The behaviour of using index and ++index inside the same assignment is unspecified in C++. You just can't just do that: write arr[index] = index + 1 and increment your variable after that. For that matter, with my C++ compiler on my machine I see arr[0] = 1, and arr[1] is untouched.

提交回复
热议问题