c++ 二维数组定义 二维数组首地址查询
程序员文章站
2022-06-11 16:53:56
#include using namespace std; int main(){ int a = 0; int arry[3][3] = { {1,2,3}, {55,66,77}, {21,34,11} }; cout << "输出地址 = " << &arry << en ......
#include <iostream> using namespace std; int main() { int arry[2][3] = { {2,3,5}, {6,7,8} }; cout << "二维数组大小 = "<< sizeof(arry) << endl; cout << "二维数组一行大小 = " << sizeof(arry[0]) << endl; cout << "二维数组元素大小 = " << sizeof(arry[0][0]) << endl; cout << "二维数组行数 = " << sizeof(arry) / sizeof(arry[0]) << endl; cout << "二维数组列数 = " << sizeof(arry[0]) / sizeof(arry[0][0]) << endl; //cout << "hello world!" << endl; //地址 cout << "二维数组首地址 = " << arry << endl; cout << "二维数组第一行地址 = " << arry[0] << endl; cout << "二维数组第二行地址 = " << arry[1] << endl; cout << "二维数组第一个元素地址 = " << &arry[0][0] << endl; cout << "二维数组第二个元素地址 = " << &arry[0][1] << endl; system("pause"); return 0; }
//===================================
#include <iostream>
using namespace std;
int main(){
int a = 0;
int arry[3][3] = {
{1,2,3},
{55,66,77},
{21,34,11}
};
cout << "输出地址 = " << &arry << endl;
cout << "二维数组第一行 = " << arry[0] << endl;
cout << "二位数组行数 =" << sizeof(arry) / sizeof(arry[0]) << endl;
cout << "二位数组列数 =" << sizeof(arry[0]) / sizeof(arry[0][0]) << endl;
cout << "二位数组占内存大小 =" << sizeof(arry) << endl;
cout << "二位数组一行占内存大小 =" << sizeof(arry[0]) << endl;
cout << "二位数组总共占内存大小 =" << sizeof(arry[0][0]) << endl;
return 0;
}
上一篇: 99乘法表(for循环嵌套)
下一篇: 本机与虚拟机Ping不通