打印不同的試圖瞭解工會的行爲無法弄清楚爲什麼printf的標準輸出
#include <stdio.h>
struct abc{
unsigned long a;
unsigned long b;
// unsigned long c;
};
union temp
{
struct abc a;
unsigned long arr[2048];
};
int main()
{
union temp temp;
temp.a.a = 3;
temp.a.b = 'a';
// temp.a.c = 2;
printf("add : 0x%x 0x%x 0x%x \n", temp.a.a, temp.a.b, temp.arr[0]);
printf("add : 0x%x 0x%x \n",temp.a,temp.arr[0]);
return 0;
}
Output:
add : 0x3 0x61 0x3
add : 0x3 0x61
問:爲什麼在第二個printf變量「temp.arr [0]」正在打印0x61,而它應該再次打印0x3?
使用'「%x」'打印'unsigned long'是未定義的行爲。使用匹配的說明符和參數。 – chux