c ++ specified when creating a variable or constant, you must first specify the appropriate data type, whether the hair can not assign a variable to memory.
1. Integer
type of data | take up space | Ranges |
short | 2 bytes | -2^15-2^15-1 |
int | 4 bytes | -2^31-2^31-1 |
long | 4 bytes of windows, Linux is 4 or 8 bytes | -2^31-2^31-1 |
long long | 8 bytes | -2^63-2^63-1 |
声明:short a = 10;int b = 10;long c = 10;long long d = 10;
sizeof keyword: Statistics for the type of share memory size, for example, sizeof (int);
2. Real (floating point)
type of data | take up space | Effective range of numbers |
floast (single precision) | 4 bytes | 7 significant digits |
double (double precision) | 8 bytes | 15-16 significant digits |
Statement: A = a float 10.123 F ; B = Double 10.123; (note later need to add single precision f) By default, the output of a decimal, six significant digits displayed , if you want to output more, need to be arranged accordingly.
3. Character
c, and c ++ variable in character occupies only 1 byte, character variable than itself into memory, but the corresponding ASCII code stored in memory.
Statement: char ch = 'a'; (note that the use of single quotes, not double quotes, and holds just a single quote character). In order to obtain the corresponding ASCII code, required to decimal, i.e., (int) a;
Escape character: like \ n, \ t, \ v, and so on. Use: cout << "hello world \ n";
4. String
Two styles:
- C-style follows: char variable name [] = "string value";
- c ++ style: string variable name = "string value";
The Boolean data type
Boolean data type is 1 byte.
Disclaimer: bool flag1 = true; bool flag1 = false; output if true, the output 1, otherwise the output is 0.