可以将结构作为函数的返回值。实例如下:
#include
#include
struct test{
int i;
char c;
double d;
float f;
};
struct test set(int a,float b,char c,double d )
{
struct test t;
t.i = a;
t.f = b;
t.c = c;
t.d = d;
return t;
}
void sig(int s );
voidprint(struct test t2)
{
printf("int:%d\n",t2.i);
printf("char:%c\n",t2.c);
printf("float:%f\n",t2.f);
printf("double:%lf\n",t2.d);
}
void sig(int s )
{
printf("捕获信号%d,跳出……",s);
exit(1);
}
int main(void)
{
struct test info;
info =set(2,3.22,'d',4.335);
print(info);
return0;
}