What is the difference between Pointer and strings?

会有一股神秘感。 提交于 2021-02-05 11:32:07

问题


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 fitst element.


回答1:


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.



来源:https://stackoverflow.com/questions/33804935/what-is-the-difference-between-pointer-and-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!