[C Language-Array Name] The difference between array name and & array name

Things to note when using array names:

1. arr is equivalent to  &arr[0] , indicating the address of the first element in the array

2. &arr   represents the first address of the entire array

As shown in the first three lines of the figure, the results of the two are the same, and they both represent addresses, that is, pointers, but the span of the pointers is different.

Specific explanation:

Attached code:

#include <stdio.h>
int main()
{
	int arr[3] = {1,2,3};
	//数组名是数组首元素的地址==&数组名[0]
	printf("%p\n", arr);     //0053F7FC
	printf("%p\n", &arr[0]); //0053F7FC
	
    //&数组名:整个数组的首地址
	printf("%p\n", &arr);    //0053F7FC
	
	//数组名和&数组名的区别
	printf("%p\n", arr+1);   //0053F800
	printf("%p\n", &arr+1);  //0053F808
							 
	return 0;
}

 

 

Guess you like

Origin blog.csdn.net/ggbb_4/article/details/129185642