//今天总算写了点
#include
using namespace std ;
struct MAX_MIN
{
int max;
int min;
};
const MAX_MIN* Get_Max_MIN(int x,int y,int z);
int main ()
{
const MAX_MIN *mn = Get_Max_MIN(1,3,5);//经过Get_Max_MIN函数执行后,由函数的返回值(返回局部静态变量temp)的指针给mn。
cout<<"三个数中最大的是"
<< mn->max
<<"\t最小的是"
<< mn->min
<
}
//Get_Max_MIN 获取三个参数中的最大和最下两个值,并返回这个2个值 用静态局部变量temp
const MAX_MIN* Get_Max_MIN(int x,int y,int z)
{
static MAX_MIN temp;
if (x>y && x>z)
temp.max = x;
if (y>x && y>z)
temp.max = y;
if (z>x && z>y)
temp.max = z;
if (x < y && x < z)
temp.min = x;
if (y < x && y < z)
temp.min = y;
if (z < y && z < x)
temp.min = z;
return &temp; //函数返回值是声明为“静态局部变量的”的temp(Max_MIN结构体)的指针。
}
没有评论:
发表评论