数组参数

三种形式

void test1(int *s)
void test2(int s[])
void test3(int s[5])

实例

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
#include <iostream>
#include <vector>
using namespace std;

// 测试字符串和字符数组的参数传递
void test1(int *s){
cout<<*(s)<<endl;
return;
}
void test2(int s[]){
cout<<*s<<endl;
return;
}
void test3(int s[5]){
cout<<*s<<endl;
return;
}

int main()
{
int s1[]={1,2,3,4,5,6,7,8};
int s2[3]={4,5,6};
int* s3 = new int(999);
test1(s3);
test2(s3);
test3(s3);
return 0;
}