If I do this in C#
int[] arr = new int[] { 0, 1 };
fixed (int* pArr = arr)
{
int* ppArr = pArr;
int val = *ppArr + *++ppArr
}
I get val = 1
. This I believe is the correct behavior.
If I do this in C++
int* const pArr = new int[2];
pArr[0] = 0;
pArr[1] = 1;
int* ppArr = pArr;
int val = *ppArr + *++ppArr;
I get val = 2
.
Can someone explain why C++ is different? Is there a way to fix it? I am using Visual Studio 2012.