非常感激我队友大爹给我的复习资料

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<bits/stdc++.h>
using namespace std;

void print_1(const int (*a)[3], const int& n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
cout << endl;
}

void print_2(const int a[][3], const int& n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
cout << endl;
}

int main() {
int a[5][3] = {{1}, {2, 2}, {3, 3, 3}};
print_1(a, 5);
int b[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
print_1(b, 3);
int c[4][3] = {1, 2, 3, 4};
print_2(c, 4);
return 0;
}
/*
该程序的输出结果为:
===================
1 0 0
2 2 0
3 3 3
0 0 0
0 0 0

1 2 3
4 5 6
7 8 9

1 2 3
4 0 0
0 0 0
0 0 0
===================
*/

传参

将多维数组a作为参数传入时,除第一个维度外,所有维度都必须有边界

指针

1
void print_2(const int a[][3], const int& n)

普通

1
void print_2(const int a[][3], const int& n)

第二个维度必须写上具体的维度,不写会报错

赋值

分行部分赋值

1
int a[5][3] = {{1}, {2, 2}, {3, 3, 3}};

全部赋值

1
int b[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};

部分赋值

1
int c[4][3] = {1, 2, 3, 4};