为什么 if( union member) 评估为 True?

Why does if( union member) evaluate as True?

 union Data {
   int i;
   char s[20];
   } data;

int main(){
   printf( "%lu\n", sizeof( data ) );
   for( int i = 0; i < 20; ++i ) {
     data.s[i] = 0;
   }
   data.i = 0;
   strcpy( data.s, "Hello World!");
   if( data.i ) {
       strcpy( data.s, "Farewell!");
   }
   printf( "%s\n", data.s ); 

为什么它响应 "Farewell"?我希望 if( data.i ) 评估为 False,但不知何故它被评估为 True

struct 不同,union 中的所有字段在内存中相互重叠。因此,如果您更改一个字段,它会影响所有其他字段。

如果您希望字段彼此不同,请改为声明 struct

struct Data {
   int i;
   char s[20];
} data;