利用结构体让函数返回多个值 发表于 2017-11-29 | 更新于: 2017-11-29 | 分类于 Programc语言123456789101112131415161718192021222324#include "stdio.h"typedef struct test //建立结构体{ int a; int b; int c;}T;T testt(int aa,int bb,int cc) //建立函数{ T aaa; aaa.a=aa*bb; aaa.b=aa*cc; aaa.c=bb*cc; return aaa; //返回结构}int main(){ T b=testt(4,5,6); printf("%d %d %d \n",b.a,b.b,b.c); T *f=&b; printf("%d %d %d",f->a,f->b,f->c);}C++123456789101112131415161718192021222324252627#include "iostream"typedef struct sss //建立结构体{ int a; int b; int c;}S;S s(double a,double b,double c) 建立函数{ S d; d.a=a*a; d.b=b*b; d.c=c*c; return d;//返回结构体}int main(){ S z=s(3,4,5); std::cout<<z.a <<std::endl <<z.b <<std::endl <<z.c <<std::endl;} 本文作者: アストルファ 本文链接: https://Asutorufa.github.io/posts/c69434f1/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!