printing a member of a returned struct
问题 I'm having trouble printing a member of a struct that is returned from a function: #include <stdio.h> struct hex_string { char a[9]; }; struct hex_string to_hex_string_(unsigned x) { static const char hex_digits[] = "0123456789ABCDEF"; struct hex_string result; char * p = result.a; int i; for (i = 28; i >= 0; i -= 4) { *p++ = hex_digits[(x >> i) & 15]; } *p = 0; printf("%s\n", result.a); /* works */ return result; } void test_hex(void) { printf("%s\n", to_hex_string_(12345).a); /* crashes */