the difference between array identifier and address of array identifier

前端 未结 4 1036
自闭症患者
自闭症患者 2021-01-14 07:23

Following program would state my doubt clearly I think,so I posted the program:

 #include 
int main() {

        int a[]={1,2,3,4,5};
                 


        
4条回答
  •  广开言路
    2021-01-14 07:46

    If I get your question right. Your int a[]={1,2,3,4,5}; I believe only stores the address of element 0 so putting this if(&a[0] == a) is probably not required. The c string theory states that an array identifier without the bracket is the address of the first element of the characters. "a" is not defined in the program. it would probably give you a stack error. I would write it this way if(&a == a[]){printf("------"); this would only compare the address of the pointer to the address of the first element of the array.

提交回复
热议问题