int a[3][3] = { 1,8,6, 4,3,5, 7,0,2 }; int* p = *(a + 1);
时间: 2024-05-27 18:11:37 浏览: 20
The value of `p` would be the address of the first element in the second row of the `a` array, which is `4`.
To break it down, `a` is a 2-dimensional array with 3 rows and 3 columns. When we access `*(a 1)`, we are dereferencing the second element in the `a` array, which is `{4,3,5}`. This is equivalent to `a[1]`.
Since `a[1]` is an array itself, we can use a pointer to access its elements. Therefore, `p` is a pointer to the first element in `a[1]`, which is `4`.
相关问题
int a[5]={1,2,3,4,5}
以下是定义和初始化int数组a的两种方法:
1.定义并初始化一个长度为5的int数组a,其中元素分别为1,2,3,4,5:
```c
int a[5] = {1, 2, 3, 4, 5};
```
2.先定义一个长度为5的int数组a,再逐个为其赋值:
```c
int a[5];
a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;
a[4] = 5;
```
int a(N)={1,5,8,7,6,3,2,4};
这不是一个合法的定义方式。如果你想定义一个数组并初始化它,应该使用以下方式:
```c++
int a[] = {1, 5, 8, 7, 6, 3, 2, 4};
```
或者
```c++
int a[8] = {1, 5, 8, 7, 6, 3, 2, 4};
```
这两种方式都可以定义一个有8个元素的整型数组,并将它们初始化为指定的值。注意,第二种方式需要显式指定数组的长度,并且长度必须与初始化列表中的元素个数相同。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)