What is the difference between Pointer and strings?

后端 未结 1 1882
清歌不尽
清歌不尽 2021-01-28 00:09

What is the difference between a pointer and array or they are same? As a array also works with poiter arithematic so it can be said that an array is nothing but pointer to its

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-28 00:44

    They both are different by the following differences:-

    int array[40];
    int * arrayp;
    

    Now if you will try to see the size of both then it will be different for pointer it will same everytime whereas for array it varies with your array size

    sizeof(array);\\Output 80
    sizeof(arrayp);\\Output 4(on 32-bit machines)
    

    Which means that computer treats all the offsprings of integers in an array as one which could not be possible with pointers.

    Secondly, perform increment operation.

    array++;\\Error
    arrayp++;\\No error
    

    If an array could have been a pointer then that pointer's pointing location could have been changes as in the second case with arrayp but it is not so.

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