今天学习了指针的两个作用
#include <stdio.h>
void getmaxandmin(int arr[], int len, int* max, int* min);
int main()
{
//指针作用2:
//函数返回多个值
//练习:
//定义一个函数,求数组的最大值和最小值,并进行返回
int arr[] = { 1,2,3,4,5,6,7,8,9 };
int len = sizeof(arr) / sizeof(int);
int max = arr[0];
int min = arr[0];
getmaxandmin(arr, len, &max, &min);
printf("最大值:%d\n", max);
printf("最小值:%d\n", min);
return 0;
}
void getmaxandmin(int arr[],int len,int*max,int*min)
{
*max = arr[0];
for (int i = 0; i < len; i++)
{
if (arr[i] > arr[0])
{
*max = arr[i];
}
}
*min = arr[0];
for (int i = 0; i < len; i++)
{
if (arr[i] < arr[0])
{
*min = arr[i];
}
}
}
标签:arr,语言,min,int,7.24,len,getmaxandmin,max
From: https://blog.csdn.net/fhgfyrsg/article/details/140670280