C/C ++ Basic Data Type
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 |
true Orfalse |
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
Void avoid; // error! A variable cannot be directly defined for the void type.
Declare multiple names:
Int a, B, c;
Int * p, y; // This structure is not conducive to reading, should be avoided as much as possible
Int v [10], * pv; // This structure is not conducive to reading, 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
int a = 0;
There is another form of initialization variable:
type identifier (initial_value) ;
For example
int a (0);