Basic Type
The C + + language has a set of basic types that correspond to the basic storage units of a computer and some common ways to use these cells to save data:
The basic data types are as follows:
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 the values:true or false. |
1byte |
true Orfalse |
float |
Floating point number. |
4bytes |
+/-3.4e +/-(digits) |
double |
Double precision floating point number. |
8bytes |
+/-1.7e +/-308 (~15 digits) |
long double |
A Long double precision floating point number. |
8bytes |
+/-1.7e +/-308 (~15 digits) |
wchar_t |
Wide character. |
2 or 4 bytes |
1 Wide character |
In addition, users can also define:
Enumeration type (enum) for a specific set of values
Type void, indicating no information
Pointer types, such as int*
Array type, e.g. char[]
Reference types, such as double&
declaring 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 than
void avoid; Wrong! The void type cannot directly define a variable.
Declare multiple names:
int a,b,c;
int *p, y;//such a structure is not conducive to reading, should try to avoid
int v[10], *pv;//such a structure is not conducive to reading, should try to avoid
Initialize Variables
The initialization variable is in the following form:
For example, initialize an integer variable of 0, for example
int a = 0;
There is another type of initialization variable:
For example
Basic data types for C + +