如何将整个数组作为参数传递给C语言中的函数?
大批
数组是一组以通用名称存储的相关项。以下是将数组作为参数传递给函数的两种方式-
将整个数组作为参数发送给函数
将单个元素作为参数发送给函数
将整个数组作为参数发送给函数
要将整个数组作为参数发送,只需在函数调用中发送数组名称。
要接收数组,必须在函数头中声明它。
示例1
#include输出结果main (){ void display (int a[5]); int a[5], i; clrscr(); printf ("enter 5 elements"); for (i=0; i<5; i++) scanf("%d", &a[i]); display (a); //调用数组 getch( ); } void display (int a[5]){ int i; printf ("elements of the array are"); for (i=0; i<5; i++) printf("%d ", a[i]); }
Enter 5 elements 10 20 30 40 50 Elements of the array are 10 20 30 40 50
示例2
让我们考虑另一个例子来了解更多关于将整个数组作为参数传递给函数的信息-
#include输出结果main (){ void number(int a[5]); int a[5], i; printf ("enter 5 elements\n"); for (i=0; i<5; i++) scanf("%d", &a[i]); number(a); //调用数组 getch( ); } void number(int a[5]){ int i; printf ("elements of the array are\n"); for (i=0; i<5; i++) printf("%d\n" , a[i]); }
enter 5 elements 100 200 300 400 500 elements of the array are 100 200 300 400 500
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话