Index, assignment and increment in one statement behaves differently in C++ and C#. Why?
- by Ivan Zlatanov
Why is this example of code behaving differently in c++ and C#.
[C++ Example]
int arr[2];
int index = 0;
arr[index] = ++index;
The result of which will be arr[1] = 1;
[C# Example]
int[] arr = new int[2];
int index = 0;
arr[index] = ++index;
The result of which will be arr[0] = 1;
I find this very strange. Surely there must be some rationale for both languages to implement it differently? I wonder what would C++/CLI output?