Linux下gcc編譯:
求解:
爲何將一個浮點型變量強制轉換爲int *指針會報錯, 但將一個char型變量強制轉換爲int * 指針則只是warning?web
#include<stdio.h> { int a = 4; float b = 4.2; char c = 'A'; int *p4 = NULL; p4 = a; //warning: assignment makes pointer from integer without a cast p4 = (int *)a; p4 = b; //error: incompatible types when assigning to type ‘int *’ from type ‘double’ p4 = (int *)b; //error: cannot convert to a pointer type p4 = c; //warning: assignment makes pointer from integer without a cast p4 = (int *)c; //warning: cast to pointer from integer of different size return 0; }