Remon Ramy
Remon Ramy

Reputation: 177

Last array element in a row and first element in the next row having the same pointer

I was working on a college assignment that required me to get a mathematical equation related to array pointers, I wrote the following code to display the pointers of all elements:

Code to the left, output to the right.

It was all smooth until I decided to convert the addresses to decimal to make my calculations easier, I used the following line of code:

size_t D = reinterpret_cast<size_t>(&X);

Once I did, somehow the last element in a row and first element in the next row returned the same address:

Marked in red

Even after I removed that line and restored my code to it's previous state, the specified elements still return the same address. I thought it might be a weird Visual Studio behavior and I tried restarting it, but the issue wasn't fixed. I'm wondering how this happened and how it can be fixed, it doesn't make sense.

Upvotes: 0

Views: 315

Answers (1)

1201ProgramAlarm
1201ProgramAlarm

Reputation: 32727

The size of your array was changed to Arr[5][4]. It won't return an error or warning as, they are all valid pointers to the 'one past the end' element of an array.

Upvotes: 1

Related Questions