//編譯環境:codeblocks+gcc #include <stdio.h> #include <stdint.h> int Fun() { uint64_t y; uint32_t x1, x2; //y = 3000 * 24000000 / 1000;//常數默認作為32位數據,臨時運算結果也是32位,溢出錯誤 //y = (uint64_t)3000 * (uint64_t)24000000 / 1000;//常數強制轉換為64位,運算正確 y = 3000ULL * 24000000ULL / 1000ULL;//常數使用64位格式,運算正確 printf("0x%llX\n", y);//輸出 x1 = (uint32_t)(y & 0xFFFFFFFF); x2 = (uint32_t)(y >> 32); printf("0x%X,0x%X \n", x1, x2);//輸出結果 } int main() { Fun(); }