(char) 的 reinterpret_cast 在這里做什么?
unsigned int aNumber = 258; // 4 bytes in allocated memory [02][01][00][00]
printf("\n is printing out the first byte i",(char)aNumber); // Outputs the first byte[02]
為什么我沒有指向它就取出第一個位元組?例如 (char*)&aNumber
i 是這樣做的嗎 = (char)*&aNumber
還是 (char) 的 reinterpret_cast 洗掉了其余的 3 個位元組,因為它是一個字符,它只分配其中一個位元組 4 個位元組?
uj5u.com熱心網友回復:
首先,reinterpret_cast是一個 C 運算子。你所展示的不是那個,而是一個 C 風格的演員表。
強制轉換是將 type 的值轉換為 typeunsigned int的值char。超出范圍值的轉換是實作定義的,但在您可能遇到的大多數實作中,這被實作為將低位位元組重新解釋為轉換后的值。
在這種特殊情況下,低位位元組aNumber的值為 0x02,因此這就是轉換為 a 時的結果char。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/412253.html
標籤:
上一篇:對指標索引運算子的困惑
