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

后端 未结 13 1532
傲寒
傲寒 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 06:42

    Even if it is legal, why depart from convention? array + 5 is shorter anyway, and in my opinion, more readable.

    Edit: If you want it to by symmetric you can write

    int* array_begin = array; 
    int* array_end = array + 5;
    

提交回复
热议问题