通过数组名引用数组
函数声明:void fun(int arr[],int n);
函数调用:int a[10]={3,7,9,11,0,6,7,5,4,2};
fun(a,10);
示例代码
#include <stdio.h>
void fun(int arr[], int n)
{
int i = 0;
for(i=0; i<n; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}
int main(int argc, const char** argv)
{
int a[5] = {1, 2, 3, 4, 5};
fun(a, 5);
return 0;
}
编译及运行结果
通过指针引用数组
函数声明:void fun(int arr[],int n);
函数调用:int a[10]={3,7,9,11,0,6,7,5,4,2};
fun(a,10);
示例代码
#include <stdio.h>
void fun(int* arr, int n)
{
int i = 0;