There are 4 data types in C language
basic data type Structural type pointer type no return value type
basic data type
Numeric type
int type: Integer type, the data of this type occupies 4 bytes under the 32-bit operating system, and 8 bytes for the 64-bit operating system.
long type, occupying 4 bytes under 32 bits and 8 bytes under 64 bits.
short type, occupying 2 bytes
char type, occupying 1 byte
float type, occupying 4 bytes
double type, occupying 8 bytes
Structural type
structure type
struct, a composite type constructed from multiple basic data types, or structures, unions, and pointers. The size depends on the sum of the sizes of other types.
//例如
typedef struct score{
int math;
int english;
}score;
struct student{
char * name;
int age;
score = {100,100};
}stu;
type of union
A union is also a type composed of a series of other types, and the size of the union depends on the size of the largest type in the union.
union A{
int a;
double c;
}A;
enum type
Since only one constant can be assigned at a time, the enumeration occupies 4 bytes.
We often define a set of related constants as an enumeration
typedef enum week{
Mon = 1, Tues, Wed, Thurs, Fri, Sat, Sun
}week;
//使用枚举
int main(){
int i = 1;
week day = (week)i;
switch(day){
case Mon: puts("Monday"); break;
case Tues: puts("Tuesday"); break;
case Wed: puts("Wednesday"); break;
case Thurs: puts("Thursday"); break;
case Fri: puts("Friday"); break;
case Sat: puts("Saturday"); break;
case Sun: puts("Sunday"); break;
default: puts("Error!");
}
return 0;
}
array type
, the array type is a collection of the same data type, which can be a structure or a union.
int a[10] = {0};
char a[10] = {0};
The array type is often used to give questions. For example, it is known that int a[3][3], the address of a[0][0] is 1000, find the address of a[2][2], and some even It is possible to find the hexadecimal address. Here, knowing that the int type occupies 4 bytes, you can calculate the number of bytes when a[2][2] is reached, and you can calculate the address of a.
pointer type
The pointer type occupies 4 bytes, int * q, char * q are 4 bytes
no return value type
void, usually defined before the function, if the current function does not have any return value, it is modified with void.