C++ 入門指南 4.01
練習 3.2 參考程式 - 練習 sizeof 運算子
// 引入標準程式庫中相關的輸入、輸出程式
#include <iostream>
// std 為標準程式庫的命名空間
using namespace std;
int main(void) {
short a = 1;
int b = 2;
long c = 3;
long long d = 4;
// 印出以上宣告的三種整數變數與 sizeof 的結果
cout << a << ":" << sizeof(a) << endl;
cout << b << ":" << sizeof(b) << endl;
cout << c << ":" << sizeof(c) << endl;
cout << c << ":" << sizeof(d) << endl;
// 最後回傳 0 給作業系統
return 0;
}
/* 《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:exercise0302.cxx
編譯:g++ exercise0302.cxx
執行:./a.out
功能:C++入門指南單元三的練習
作者:張凱慶 */
回到練習題目