#include<stdio.h>
int main(){
int arr[10] = {0};
printf("%p\n",arr);
printf("%p\n",&arr);
return 0;
}
Although the results of the above code printout are the same, the meanings are different
printf("%p\n",arr); This means that the address of the first element of the array is printed
printf("%p\n",&arr); This is to print the address of the array
These two types are different
for example
#include<stdio.h>
int main (){
int i = 97;
char c = 'a';
printf("%d\n",i);
printf("%d\n",c);
return 0;
}
The values printed by both are integers are the same, but their types are different
2.
int main(){
int arr[10] = {0};
int * p1 = arr; //p1是一个整型指针
int (*p2) [10] = &arr; //p2是一个数组指针
printf("%p\n",p1);
printf("%p\n",p2);
return 0 ;
}
Note the following code
int main(){
int arr[10] = {0};
int * p1 = arr; //p1是一个整型指针
int (*p2) [10] = &arr; //p2是一个数组指针
printf("%p\n",p1);
printf("%p\n",p1+1); //这里指针+1 会跳过一个整型的指针(即跳过四个字节)
printf("%p\n",p2);
printf("%p\n",p2+1); //这里指针+1 会跳过一个整型数组的指针(即跳过40个字节)
return 0 ;
}
Output result:
When we take the address, &arr represents the address of the array, not the address of the first element of the array
//练习
double* d[5]; //d数组的每个元素 每个元素是double*类型的
double* (*pd)[5] = &d;
//pd 就是一个数组指针
//(*pd)[5] 这个说明 指针指向的是数组5个元素
//double* (*pd)[5] = &d; 这个说明 指针指向的是数组5个元素,指向的每个元素是double* 类型的
Replenish:
The array name is the address of the first element of the array
with two exceptions
1. sizeof(array name) - the array name represents the entire array, and the calculation is the size of the entire array, in bytes
2. &Array name- The array name indicates that the address of the entire array is retrieved from the entire array