#include<bits/stdc++.h>
using namespace std;
int main(){
int arr[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
int* p = &arr[0][0]; // 获取数组首元素指针
int *q = arr[0]; // 等价于p
// 获取行指针
int (*row_ptr)[4] = arr; // 指向首行的指针
cout << "Row 1: ";
for(int i=0; i<4; i++) cout << row_ptr[0][i] << " "; // 输出首行元素
// 获取列指针
int* col_ptr = &arr[0][0]; // 指向首列的指针
cout << "\nColumn 1: ";
for(int i=0; i<3; i++) cout << col_ptr[i*4] << " "; // 输出首列元素
cout << "\n*(q+1): " << *(q+1); // 输出第二列首元素
return 0;
}
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com