- 外層循環打印行數,內層循環打印列數
點擊查看代碼
#include<iostream>
#include<string>
using namespace std;
int main()
{
//2. 數據類型數組名[ 行數 ][ 列數 ] = { {數據1,數據2 },{數據3,數據4 } };
int arr[2][3] =
{
{1,2,3},
{4,5,6}
};
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 3; j++)
{
cout << arr[i][j] << " ";
}
cout << endl;
}
//4.數據類型數組名[ ][ 列數 ] = { 數據1,數據2,數據3,數據4 };
int arr01[][3] = { 11,21,31,41,51,61 };
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 3; j++)
{
cout << arr01[i][j] << " ";
}
cout << endl;
}
system("pause");
return 0;
}
點擊查看代碼
int arr[2][3] =
{
{1,2,3},
{4,5,6}
};
cout << "二維數組所占內存空間:" << sizeof(arr) << endl;
cout << "二維數組第一行占內存空間:" << sizeof(arr[0]) << endl;
cout << "二維數組第一個元素占內存空間:" << sizeof(arr[0][0]) << endl;
點擊查看代碼
cout << "二維數組首地址:" << (int)arr << endl;
cout << "二維數組第一行首地址:" << (int)arr[0] << endl;
cout << "二維數組第一個元素首地址:" << (int)&arr[0][0] << endl;
cout << "二維數組第二行首地址:" << (int)arr[1] << endl;