1、
#include <stdio.h> struct xyz{ int x; long y; double z; }; struct xyz input(int a, long b, double c) { struct xyz tmp; tmp.x = a; tmp.y = b; tmp.z = c; return tmp; } int main(void) { struct xyz result; int i; long j; double k; printf("i = "); scanf("%d", &i); printf("j = "); scanf("%ld", &j); printf("k = "); scanf("%lf", &k); result = input(i, j, k); printf("result.x = %d ", result.x); printf("result.y = %ld ", result.y); printf("result.z = %lf ", result.z); return 0; }
2、
#include <stdio.h> struct xyz{ int x; long y; double z; }; struct xyz scan_xyz(void) { struct xyz tmp; printf("tmp.x = "); scanf("%d", &tmp.x); printf("tmp.y = "); scanf("%ld", &tmp.y); printf("tmp.z = "); scanf("%lf", &tmp.z); return tmp; } int main(void) { struct xyz result; result = scan_xyz(); puts(" ======================"); printf("result.x = %d ", result.x); printf("result.y = %ld ", result.y); printf("result.z = %f ", result.z); return 0; }