我试图使用结构来使用以下代码返回多个变量。使用c函数返回多个变量
有没有更好的方法来做到这一点?
和这种技术,它是有效的? PS:我是新来的嵌入式系统,所以试图发现内存,性能和这些限制的最佳技术。
#include <stdio.h>
struct two func(int , int);
struct two {
int x;
int y;
};
int main() {
printf("values is\n %i\n %i\n ",func(33,44).x,func(33,44).y);
return 0;
}
struct two func(int x, int y) {
struct two ex;
ex.x=x;
ex.y=y;
return ex;
};
高效?比较什么? –
从可读性的角度来说,我会说,使用单独的函数作为getter/setter。 –
缩进你的代码。 –