由于地址运算符而造成的数组例子混乱;

时间:2019-01-24 23:15:46

标签: c arrays integer

#include <stdio.h>

int main(){

int arr[10];

arr[0] =21474836;

  printf("Adress was indicated as  &arr     is   %p\n\n",&arr);                     
  printf("Adress was indicated as  arr      is   %p\n\n",arr);            
  printf("Adress was indicated as  &arr[0]  is   %p\n\n",&arr[0]);            
  printf("Value of first element of integer array which is arr[0] is %d\n",arr[0]);

  return 0;
}

当我编译这段代码时,我遇到了;

 Adress was indicated as  &arr     is   0x7ffeabd200b0

 Adress was indicated as  arr      is   0x7ffeabd200b0

 Adress was indicated as  &arr[0]  is   0x7ffeabd200b0

 Value of first element of integer array which is arr[0] is 21474836

作为输出。

我没有期望的输出,因为我使用了地址运算符;

arr  --> it should refer  adress of first element         ;
&arr --> it should refer adress of adress of first element ;

最后,

为什么arr和&arr指的是同一件事?

0 个答案:

没有答案