Arrays with 0 elements

arrays, c++, pointers

Solution

Not at all.

In the case of arr[0], arr has a well defined address.

In the case of *arr, arr is just uninitialized.

After your EDIT, where you initialize the const arr with an array defined just before : there would just be no difference in the content of the variables, but in the actions you would be allowed to perform on them.

Problem

Is an array with 0 elements the same as an unallocated pointer? Is `int arr[0];` the same as `int* arr;`? Edit: What if I did something similar to this: ``` int x[0]; int* const arr = x; ``` I tried this code and it compiled. To my knowledge, both x and arr should be pointing to the same location in memory. What would be the difference in this case?

Original source

Related problems