1. #include <iostream>
    2. using namespace std;
    3. int main() {
    4. // 二维数组定义方式
    5. /*
    6. * 1. 数组类型 数组名 [行数] [列数];
    7. * 2. 数组类型 数组名 [行数] [列数] = {{数据1,数据2}, {数据3,数据4}}
    8. * 3. 数组类型 数据名 [行数] [列数] = {数据1,数据2,数据3,数据4}
    9. * 4. 数组类型 数组名 [] [列数] = {数据1,数据2,数据3,数据4}
    10. */
    11. // 1.
    12. int arr[2][3];
    13. arr[0][0] = 1;
    14. arr[0][1] = 2;
    15. arr[0][2] = 3;
    16. arr[1][0] = 4;
    17. arr[1][1] = 5;
    18. arr[1][2] = 6;
    19. // 外层循环打印行数, 内层循环打印列数
    20. for (int i = 0; i < 2; i++) {
    21. for (int j = 0; j < 3; j++) {
    22. cout << arr[i][j] << endl;
    23. }
    24. }
    25. // 2.
    26. int arr2[2][3] = {
    27. {1, 2, 3},
    28. {4, 5, 6}
    29. };
    30. cout << "arr2 = " << endl;
    31. // 外层循环打印行数, 内层循环打印列数
    32. for (int i = 0; i < 2; i++) {
    33. for (int j = 0; j < 3; j++) {
    34. cout << arr2[i][j] << " ";
    35. }
    36. cout << endl;
    37. }
    38. // 3.
    39. int arr3[2][3] = {1, 2, 3, 4, 5, 6};
    40. // 外层循环打印行数, 内层循环打印列数
    41. cout << "arr3 = " << endl;
    42. for (int i = 0; i < 2; i++) {
    43. for (int j = 0; j < 3; j++) {
    44. cout << arr3[i][j] << " ";
    45. }
    46. cout << endl;
    47. }
    48. // 4.
    49. int arr4[][3] = {1, 2, 3, 4, 5, 6};
    50. cout << "arr4 = " << endl;
    51. for (int i = 0; i < 2; i++) {
    52. for (int j = 0; j < 3; j++) {
    53. cout << arr4[i][j] << " ";
    54. }
    55. cout << endl;
    56. }
    57. return 0;
    58. }