//************************************************************
//变量、数据类型
//变量名是下划线、字母开头的并以且只能以下划线、字母、数字组成的标识符。区分大小写
//变量名不能使保留字名相同。例如int是保留名,不能做变量名。
//下面的都不能作变量标识 Identifiers
asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while
下面的有时不能作变量名
and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq
基本数据结构 Fundamental data types
Name | Description | Size* | Range* |
---|
char | Character
or small integer. | 1byte | signed: -128 to 127 unsigned: 0 to 255 |
short int (short ) | Short
Integer. | 2bytes | signed: -32768 to 32767 unsigned: 0 to 65535 |
int | Integer. | 4bytes | signed:
-2147483648 to 2147483647 unsigned: 0 to 4294967295 |
long int (long ) | Long integer. | 4bytes | signed:
-2147483648 to 2147483647 unsigned: 0 to 4294967295 |
bool | Boolean value. It can take one of two values: true or false. | 1byte | true or false |
float | Floating
point number. | 4bytes | +/- 3.4e +/- 38 (~7 digits) |
double | Double
precision floating point number. | 8bytes | +/- 1.7e +/- 308 (~15 digits) |
long double | Long
double precision floating point number. | 8bytes | +/- 1.7e +/- 308 (~15 digits) |
wchar_t | Wide
character. | 2 or 4 bytes | 1 wide character |
声明变量
Declaration of variables
unsigned short int NumberOfSisters;
signed int MyAccountBalance;
变量范围
上图少了页面范围内的static,局部内的static
变量初始化
int a = 0;
int a(0);
C和C++字符串
string mystring = "This is a string"; string mystring ("This is a string");
|