簡單變量
1.#include
定義了符號常量來表示類型的限制 包含下面類似的語句行: #define INT_MAX32767
2.int n_int = INT_MAX;
int的最大值
3.也可以使用字面值常量來初始化 :int uncles = 5; 注意順序 uncles必須在最前
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int aunt = uncles;?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int chairs = aunts + unles + 4;
以上方法來自C語言,C++還有另一種初始化語法 :int owls = 101;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int wrens(432);
C++11 初始化方式 :int hamburgers = {24};
? ? ? ? ? ? ? ? ?int emus{7};? 可以使用 = 也可以不使用
? ? ? ? ? ? ? ? ? ?int rocs = {};
? ? ? ? ? ? ? ? ? int psychics{];? 大括號為空表示初始化為 0?
4.sizeof 運算符產(chǎn)生類型或變量的大小
5.#include
如果超越了限制 , 其值將為范圍另一端的取值
6.cout << "cheat = " << chest << " (42 in decimal)\n"; //dec指示cout以十進制格式顯示整數(shù)
cout << "waist = " << waist << " (0x42 in hex)\n";? ? ? //hex指示cout以十六進制格式顯示整數(shù)
cout << "inseam = " << inseam << " (042 in octal)\n";? ? //oct指示cout以八進制格式顯示整數(shù)