P
Peter
Assume we have an array:
int arr[5];
It's legal to refer to address arr + 5, but, of course, illegal to refer toelement arr[5] as it's not part of the array. However, arr + n is equivalent to &arr[n]. My question is: does this equivalence also hold for an edge case of
n = 5 (or, generally, n equal to number of elements of array)?
While there's nothing wrong with arr + 5, &arr[5] looks highly suspicious: it looks like in the first step arr[5] is evaluated (which introduces an undefined behaviour) which would mean the expression as a whole is undefined.Does the equivalence still hold in this special case?
int arr[5];
It's legal to refer to address arr + 5, but, of course, illegal to refer toelement arr[5] as it's not part of the array. However, arr + n is equivalent to &arr[n]. My question is: does this equivalence also hold for an edge case of
n = 5 (or, generally, n equal to number of elements of array)?
While there's nothing wrong with arr + 5, &arr[5] looks highly suspicious: it looks like in the first step arr[5] is evaluated (which introduces an undefined behaviour) which would mean the expression as a whole is undefined.Does the equivalence still hold in this special case?