Take the address of a one-past-the-end array element via subscript: legal by the C++ Standard or not?

后端 未结 13 1374
傲寒
傲寒 2020-11-22 06:34

I have seen it asserted several times now that the following code is not allowed by the C++ Standard:

int array[5];
int *array_begin = &array[0];
int *ar         


        
相关标签:
13条回答
  • 2020-11-22 07:04

    If your example is NOT a general case but a specific one, then it is allowed. You can legally, AFAIK, move one past the allocated block of memory. It does not work for a generic case though i.e where you are trying to access elements farther by 1 from the end of an array.

    Just searched C-Faq : link text

    0 讨论(0)
提交回复
热议问题