c++ 二維數組定義 二維數組首地址查詢


#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;

}




 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM