Difference Between *(Pointer + Index) and Pointer[]

后端 未结 8 2183
日久生厌
日久生厌 2020-11-27 03:56
int* myPointer = new int[100];

// ...

int firstValue = *(myPointer + 0);
int secondValue = myPointer[1];

Is there any functional difference betwe

8条回答
  •  死守一世寂寞
    2020-11-27 04:19

    Functionally, they are identical.

    Semantically, the pointer dereference says "Here's a thing, but I really care about the thing X spaces over", while the array access says "Here's a bunch of things, I care about the Xth one."

    In most cases, I would prefer the array form.

提交回复
热议问题