Pointer to an array and Array of pointers

前端 未结 6 2063
感动是毒
感动是毒 2020-12-22 00:47

As I am just a learner, I am confused about the above question. How is a pointer to an array different from array of pointers? Please explain it to me, as I will have to exp

6条回答
  •  我在风中等你
    2020-12-22 01:45

    An array of pointers is this - int* arr[3]; will contain multiple pointers pointing to 3 different variables Pointer to an array is this - int (*arr)[3]; will point to first element of an array of 3 elements

    Below is a sample code which might help you more

        int array[3];
    array[0] = 1;
    array[1] = 2;
    array[2] = 3;
    
    int* point = array; // pointer of an array
    
    
    int* points[3];
    
    points[0] = &array[0];
    points[1] = &array[1];
    points[2] = &array[2]; // an array of pointer
    

提交回复
热议问题