如何将整个数组作为参数传递给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 国庆求婚祝福语简短精辟