Board logo

標題: 陣列(六) -sizeof [打印本頁]

作者: 周政輝    時間: 2017-7-15 08:54     標題: 陣列(六) -sizeof

利用sizeof 查看每一個資料型態當中 所佔的記憶體空間位置是多少
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     //sizeof() =>取得該型別所佔的記憶體空間
  8.      
  9.    /* int => 4Byte
  10.     string => 4Byte
  11.     char =>  中文 4Byte 英文 1Byte
  12.     float => 4Byte
  13.     Double => 8Byte*/
  14.      
  15.     cout << "int :" << sizeof(int) << endl;
  16.     cout << "string :" << sizeof(string) << endl;
  17.     cout << "char :" << sizeof(char) << endl;
  18.     cout << "float :" << sizeof(float) << endl;
  19.     cout << "double :" << sizeof(double) << endl;
  20.    
  21.    
  22.     system("pause");
  23.     return 0;   
  24. }
複製代碼

作者: 高品溫    時間: 2017-7-15 09:00

此帖僅作者可見
作者: 高睿辰    時間: 2017-7-15 09:00

此帖僅作者可見
作者: 莊旻叡    時間: 2017-7-15 09:02

此帖僅作者可見




歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2