您的位置:首页 > 其它

使用结构体的形式使一个函数返回多个数据

2017-08-18 16:29 337 查看
在进行嵌入式编程的时候经常会遇到需要返回多个数值的情况这时候就需要使用结构体了,能够一次return 多个数据,再分别取结构体中的数据去使用。

#include <stdio.h>
#include <string.h>
typedef struct
{
int x;
int y;
float z;
}can_t;

can_t get_value(can_t temp)
{
temp.x =2;
temp.y =3;
temp.z =0.23;
return temp;
}

int main()
{
can_t can_text;
can_text=get_value(can_text);
printf("can_text.x = %d\n",can_text.x);
printf("can_text.y = %d\n",can_text.y);
printf("can_text.z = %f\n",can_text.z);
return 0;
}


在GCC中的运行结果如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐