int a和 int a的區別

2021-06-04 00:58:49 字數 622 閱讀 1835

[cpp]view plain

copy

#include 

#include 

#include 

using

namespace

std;  

intmain()    

(int&)a == static_cast (a) 

(int)&a == reinterpret_cast (&a); 

(int&)a 不經過轉換, 直接得到a在記憶體單元的值,並將其轉換成整數輸出。

(int)a a在記憶體中的值轉換成int型別 

float型別在記憶體中儲存的形式是 ,符號位 指數 尾數 

由754標準:階碼採用增碼(該數補碼的反符號),尾數採用原碼 

所以1.0f 在記憶體中的形式為 

0011 1111 1000 0000 0000 0000 0000 0000 

所以輸出的是 0x3f800000

0 在記憶體中的的儲存形式 

0000 0000 0000 0000 0000 0000 0000 0000

所以輸出的是0x00000000

所以前面乙個是false,後面乙個是true。

int a和 int a的區別

先從一到面試題說起 includeusing namespace std int main 輸出結果為 0 0 5 66在上面已經知道float型125.5在記憶體中存放方式為 00000000 低位址 00000000 11111011 01000010 高位址 因此對於p和p 1指向的單元,其中...

int a和 int a的區別

float a 1.0f cout int a endl cout int a endl cout boolalpha int a int a endl 1 輸出什麼?float b 0.0f cout int b endl cout int b endl cout boolalpha int b ...

int a和 int a的區別

float a 1.0f cout int a endl cout int a endl cout boolalpha int a int a endl 1 輸出什麼?float b 0.0f cout int b endl cout int b endl cout boolalpha int b ...