
数组
数组是一组具有相同名称的相关项。以下是将数组作为参数传递给函数的两种方式:
- 将整个数组作为参数传递给函数
- 将单个元素作为参数传递给函数
将整个数组作为参数传递给函数
要将整个数组作为参数传递,只需在函数调用中发送数组名称。
要接收一个数组,必须在函数头中声明。
Python精要参考 pdf版下载这本书给出了一份关于python这门优美语言的精要的参考。作者通过一个完整而清晰的入门指引将你带入python的乐园,随后在语法、类型和对象、运算符与表达式、控制流函数与函数编程、类及面向对象编程、模块和包、输入输出、执行环境等多方面给出了详尽的讲解。如果你想加入 python的世界,David M beazley的这本书可不要错过哦。 (封面是最新英文版的,中文版貌似只译到第二版)
示例1
#includemain (){ 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); //calling array 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
让我们考虑另一个示例,以了解有关将整个数组作为参数传递给函数的更多信息 -
立即学习“C语言免费学习笔记(深入)”;
#includemain (){ void number(int a[5]); int a[5], i; printf ("enter 5 elements "); for (i=0; i<5; i++) scanf("%d", &a[i]); number(a); //calling array getch( ); } void number(int a[5]){ int i; printf ("elements of the array are
"); for (i=0; i<5; i++) printf("%d
" , a[i]); }
输出
enter 5 elements 100 200 300 400 500 elements of the array are 100 200 300 400 500










