Basic Type
The C/C ++ language has a set of basic types, which correspond to the basic storage units of computers and some common ways to use these units to save data:
The basic data types are as follows:
| Name |
Description |
Size * |
Range * |
Char |
Character or small integer. |
1 byte |
Signed:-128 to 127 Unsigned: 0-255 |
Short int(Short) |
Short integer. |
2 bytes |
Signed:-32768 to 32767 Unsigned: 0-65535 |
Int |
Integer. |
4 bytes |
Signed:-2147483648 to 2147483647 Unsigned: 0-4294967295 |
Long int(Long) |
Long integer. |
4 bytes |
Signed:-2147483648 to 2147483647 Unsigned: 0-4294967295 |
Bool |
Boolean value. It can take one of two values: true or false. |
1 byte |
TrueOrFalse |
Float |
Floating Point Number. |
4 bytes |
+/-3.4e +/-38 (~ 7 digits) |
Double |
Double Precision Floating Point Number. |
8 bytes |
+/-1.7e +/-308 (~ 15 digits) |
Long double |
Long Double Precision Floating Point Number. |
8 bytes |
+/-1.7e +/-308 (~ 15 digits) |
Wchar_t |
Wide character. |
2Or4 bytes |
1 wide character |
In addition, you can also define:
Enumeration type of a group of specific values (Enum)
Type void, indicating no information
Pointer type, such as int *
Array type, such as char []
Reference type, such as double &
Declare Variables
Int A;
Float Mynumber;
Const Double Pi = 3.1415926 ;
Extern Int Error_number;
Const Char * Name = " Blue " ;
Const Char * Season [] = { " Spring " , " Summer " , " Fall " , " Winter " };
Void cannot directly define a variable other
VoidAvoid;//Error! A variable cannot be directly defined for the void type.
Declare multiple names:
IntA, B, C;
Int* P, Y;//This structure is not conducive to reading and should be avoided as much as possible
IntV [10], * PV;//This structure is not conducive to reading and should be avoided as much as possible
Initialize variable
The initialization variables are as follows:
Type identifier = initial_value;
For example, initialize an integer variable to 0, for example
IntA =0;
There is another form of initialization variable:
Type identifier (initial_value );
For example
IntA (0);