c++ - 数组与指针的问题
迷茫
迷茫 2017-04-17 14:18:02
0
2
435
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
左手右手慢动作

arr[0] is a one-dimensional array,
&arr[0] is a pointer to a one-dimensional array,
&arr[0]+1 is also a pointer to a one-dimensional array, *(&arr[0]+1) is a one-dimensional array, and the array is When making an rvalue, it is automatically converted into a pointer. This is the explanation in C language

arr[0] is an array, and &arr[0] is a pointer to the array. In fact, it can also be understood as the address of arr[0], but the compiler knows its type, so it is called a pointer. But there is no place in the actual memory to store the address of &arr[0] or arr[0]. It is not like the variable b. b is declared and the compiler allocates memory space to it, so you can use the address & to get the address of b.

arr is an array, and each member of it is an array int [2]. The length of each member is 8 bytes. arr + 1 is converted into a pointer to the array when doing this operationint (*)[2], so the value of arr + 1 is the address of array arr + 8. It is not only an address, but the compiler knows the type of data it points to. This is a pointer in the concept of C language. So *(arr+1) is arr[1].

*(arr+1) represents the content in the memory, but this content happens to be an array. The array is automatically converted into a pointer to the array member, so what is printed is the address. If it is int arr1[2], then *(arr1 + 1) is different.

大家讲道理
&arr[0] 相当于 arr
&arr[0] + 1  相当于 arr + 1
*(arr + 1) 相当于 arr[1] 所以还是地址

Related topics

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template