變量
整型數(shù)及相關(guān)
查詢int
、long
夕凝、short
的長度:
#include <climits>
int n_int = INT_MAX;
short n_short = SHRT_MAX;
long n_long = LONG_MAX;
long long n_llong = LLONG_MAX;
sizeof variable
返回的是字節(jié)長度:
cout << "short is " << sizeof n_short << " bytes." << endl;
// short is 2 bytes.
cout << "int is " << sizeof(int) << " bytes." << endl;
// int is 4 bytes.
無符號變量unsigned int
亡脑。
cout << "Enter your agent code:________\b\b\b\b\b\b\b\b";
long code;
cin >> code;
// 將在打印完下劃線后退回第一個下劃線前等待輸入
布爾值
只有零值才為false
,其他均為true
:
bool start = -100; // start = true
bool end = 0; // end = false
const
限定符
const
比#define
好:
- 可以指明類型
- 可以將常量定義限制在一定范圍內(nèi)
- 可以用于更復雜的結(jié)構(gòu)往扔,如數(shù)組