我有一個80元素char
數組,我試圖將某個元素指定爲integer
,並且出現了一些數字錯誤。 十六進制中的數組元素40是0xC0。當我嘗試將它分配到一個integer
我得到在十六進制0xFFFFC0,我不知道爲什麼。將字符數組中的元素轉換爲int
char tempArray[80]; //Read in from file, with element 40 as 0xC0
int tempInt = (int)tempArray[40]; //Output as 0xFFFFC0 instead of 0x0000C0
由於在''char''中''0XC0''爲負數,並且演員將該符號保存爲''int''。 – aruisdante
'int tempInt =(int)tempArray [40];' - >'unsigned tempInt =(unsigned)tempArray [40];'會做的。 – dasblinkenlight