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

后端 未结 8 2187
日久生厌
日久生厌 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:17

    Actually , When an Array 'a' is initialized a pointer to its first memory location ie.. a[0] is returned which is nothing but a ;

    So if you do 'a+1' it is actually a pointer to a[1]

    if you do 'a+2' it is actually a pointer to a[2]

    if you do 'a+3' it is actually a pointer to a[3] so on ,

    so if you do *(a+1) you will get value of a[1] and similar for other values also. if you do *(a) you actually get a[0], So i think its pretty clear now how it works..

提交回复
热议问题