close

按此前往C++完整教學目錄

 

 

sizeof()函式:

可以檢查變數或者資料形態所占據的記憶空間大小(回傳值為整數資料形態,以位元組為單位)

如:sizeof(對象); //對象,可為變數名稱或資料形態名稱。

範C++例如:

int i=10;

float f=5.5;

double d=4.6543;

char c='d';

cout<<sizeof(i)<<endl;  //顯示4,表示變數i占有4個位元組(4 bytes)

cout<<sizeof(f)<<endl;  //顯示4,表示變數f占有4個位元組(4 bytes)

cout<<sizeof(d)<<endl;  //顯示8,表示變數d占有8個位元組(8 bytes)

cout<<sizeof(c)<<endl;  //顯示1,表示變數c占有1個位元組(1 byte)

cout<<sizeof(int)<<endl;  //顯示4,表示資料形態int占有4個位元組(4 bytes)

cout<<sizeof(float)<<endl;  //顯示4,表示資料形態float占有4個位元組(4 bytes)

cout<<sizeof(double)<<endl;  //顯示8,表示資料形態double占有8個位元組(8 bytes)

cout<<sizeof(char)<<endl;  //顯示1,表示資料形態char占有1個位元組(1 bytes)

cout<<sizeof(bool)<<endl;  //顯示1,表示資料形態bool占有1個位元組(1 bytes)

 

 

上一篇:c++ sleep

下一篇:數學函數

arrow
arrow

    埃伯 發表在 痞客邦 留言(0) 人氣()