欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c++ 二维数组定义 二维数组首地址查询

程序员文章站 2023-11-02 16:01:52
#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;

}