Data types in C language(basic, structure, pointer and void types)

Lionsure 2020-09-04 Original by the website

Data types in C language are divided into basic, structure, pointer and void types. The basic types are divided into numeric and character types; numeric types are divided into integer and floating-point types. The structure type is divided into array, structure, union and enumeration type.

 Some basic types(int, char) can be modified with signed, unsigned, short and long. signed and unsigned can modify int and char; short and long can modify int and double. General modifiers are not considered basic types, and not only different books have different definitions.

 

Data types in C language

One, basic types

I) Numerical

1. integer

1) short int

The short int represents a short integer type, which can be abbreviated as short, ranging from -32768 to +32767, a 16-bit integer.

 

2) int

The int represents an integer, ranging from -32768 to +32767, a 16-bit integer.

 

3) unsigned int

The unsigned int represents an unsigned integer, ranging from 0 to 32767, a 16-bit integer.

 

4) unsigned short int

The unsigned short int represents an unsigned short integer, which can be abbreviated as unsigned short, ranging from 0 to 32,767, a 16-bit integer.

 

5) long int

The long int represents a long integer, which can be abbreviated as long, ranging from -2,147,483,648 to 2,147,483,647, a 32-bit integer.

 

6) unsigned long int

The unsigned long int represents an unsigned long integer, which can be abbreviated as unsigned long, ranging from 0 to 2,147,483,647, a 32-bit integer.

 

7) long long int

The long long int represents a long integer type, which can be abbreviated as long long, ranging from -9223372036854775808 to +9223372036854775807, a 64-bit integer.

 

2. Floating point

1) float

 The float represents a single-precision type storing 32-bit floating-point values, ranging from -3.4e-38 to 3.4e38, with a precision of 7 bits.

 

2) double

The double represents a double-precision type storing 64-bit floating-point values, ranging from 1.7e-308 to 1.7e308, with a precision of about 16 bits.

 

3) long double

The long double represents a long double precision type storing 128-bit floating point values, ranging from 3.4e-4932 to 1.1e4932, with a precision of about 19 bits.

 

II) Character type(char)

The char is used to store characters. The length is 8 bits per byte. There are 3 types, namely char, signed char and unsigned char. Whether char is signed char or unsigned char depends on the editor.

 The range of signed char is -128 to 127; the range of unsigned char is 0 to 255.

 

 

Two, structure type

1. array

 The array is a combined data type, divided into one-dimensional array and multi-dimensional array, and the subscript starts from 0. For example, define an integer one-dimensional array int a[6]={ 0,1,2,3,4,5}, define a character two-dimensional array char s[5][5].

 

2. structure(struct)

The struct refers to a collection of multiple single data, much like a record in a database, and the variables defined in the structure are very similar to the fields of record. Definition form:

struct identifier

{

       member list

};

 

3. union

The union is also used to describe data of different types, but unlike struct, data members are stored using overlay technology to share storage space, that is, data members occupy the same storage unit in memory. Definition form:

union identifier

{

       member list

};

 

4. enumeration type (enum)

The enum is used to declare a set of named constants, the definition form:

enum identifier

{

       enumerated data table

};

 

Three, pointer type

Pointer refers to the address of the variable, which is essentially the address of the storage unit. According to the different types of variables, they are divided into integer pointers(int *), floating-point pointers(float *), character pointers(char *), structure pointers(struct *) and union pointers(union *).

 

Four, empty type(void)

The void literally means "empty type", "void *" is a "null type pointer", "void *" can point to any type of data. It has two main purposes: on the one hand, it is clear that a function does not return any value; on the other hand, it is to define a pointer that does not point to any address, and then point it to a specific address when needed.