Does an Array variable point to itself?

前端 未结 4 1821
猫巷女王i
猫巷女王i 2021-01-23 11:14

I tried some code to check the behavior of array and pointers. Its as follows.

#include 
main(){
int s[]={1,2};
int *b=s;
printf(\"%d, %d, %d\\n\"         


        
4条回答
  •  执念已碎
    2021-01-23 12:07

    A simple way to think about this is that an array as a pointer can't be changed by assignment, it is effectively a constant pointer to a known amount of memory.

    To try that, use:

    myptr = myarray;
    

    Which is perfectly ok, and then try:

    myarray = myptr;
    

    Which is not.

提交回复
热议问题