C语言中return语句怎样返回两个或多个值

来源:百度知道 编辑:UC知道 时间:2024/07/03 11:00:31
请高手看看我的程序
输入两个数,输出最大值和 最大值+100。
主函数调用max函数,我想知道max函数怎样返回两个值给主函数,
我这个程序不知有什么错误,运行时我输入123,45 却输出得到Max=123,3
我这程序应怎样改?
#include "stdio.h"
void main()
{int max(int x,int y,int z,int h);
int a,b,c,d;
scanf("%d,%d",&a,&b);
c=max(a,b,c,d);
printf("Max is %d,%d",c,d);
}
int max(int x,int y,int z,int h)
{z=x>y? x:y;
return z;
h=z+100;
return h;
}
不好意思,程序我漏了一句,在第六句c=max(a,b,c,d);后面还有一句d=max(a,b,c,d);

return语句不能直接返回多个值。如果想通过函数内部返回多个值的话,可是使用以下代码:

#include <stdio.h>

//定义一个s

typedef struct _a

{

int a;

int b;

}A,*PA;

//函数返回结构体变量,它里面就可以包含多个值

PA func()

{

PA a = (A*)malloc(sizeof(A));

a->a = 2;

a->b = 3;

return a;

}

int main()

{

PA test = func();

printf("%d %d\n", test->a, test->b);

delete test;

return 0;

}

关于C 语言中 return 语句的疑问 c语言中函数的return语句之后还可以再有别的语句麽? c语言里 return语句是不是代表函数结束 C语言中return的用法??? C语言中return的含义? c语言中return的用法 一个c语言中return的用法? c语言中return的作用是什么 C语言 return (*a)++ c语言return