返回指针的函数的定义及调用
// 返回指针的函数
#include <stdio.h>
#include <string.h>
int *find_max(int *p, int n) //function prototype: data_type *function_name( ... )
{
int i, *max = p;
for(i=0; i<n; ++i,++p)
{
if(*max<*p)
max = p;
}
return max;
}
int main()
{
int a[10], *max, i;
printf("Please input ten integer:\n");
for(i = 0; i<10; i++)
{
scanf("%d", &a[i]);
}
max = find_max(a, 10); //calling convention: 函数无须*,函数返回的是地址,所以前面用pointer而不是*pointer来接收。
printf("The maximum number is: %d\n", *max);
return 0;
}
!!!!!!!!!编程之路,你我为伴!!!!!!!!!