In the C language, data types refer to a broad system used to declare different types of variables or functions. The type of a variable determines the amount of space it occupies in storage and how the stored bit patterns are interpreted.
| Index | Type and Description | 
|---|---|
| 1 | Basic Data Types These are arithmetic types, including integer (int), character (char), floating-point (float), and double-precision floating-point (double). | 
| 2 | Enumeration Type: These are also arithmetic types used to define variables that can only be assigned certain discrete integer values in the program. | 
| 3 | Void Type: The type specifier void indicates a data type with no value, typically used for function return values. | 
| 4 | Derived Types: Include array types, pointer types, and structure types. | 
Array types and structure types are collectively referred to as aggregate types. The type of a function refers to the type of its return value. In the following sections, we will introduce basic types, with the remaining parts covered later.First, let’s understand integer types.The table below lists details about the storage size and value range of standard integer types:
| Specific Type and Name | Storage Size | Value Range | 
|---|---|---|
| char (character type) | 1 byte | -128 to 127 or 0 to 255 | 
| unsigned char (unsigned character type) | 1 byte | 0 to 255 | 
| signed char (signed character type) | 1 byte | -128 to 127 | 
| int (integer type) | 2 or 4 bytes | -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 | 
| unsigned int (unsigned integer type) | 2 or 4 bytes | 0 to 65,535 or 0 to 4,294,967,295 | 
| short (short integer = short int) | 2 bytes | -32,768 to 32,767 | 
| unsigned short (unsigned short integer) | 2 bytes | 0 to 65,535 | 
| long (long integer = long int) | 4 bytes | -2,147,483,648 to 2,147,483,647 | 
| unsigned long (unsigned long integer) | 4 bytes | 0 to 4,294,967,295 | 
Note: The storage size of various types depends on the system architecture, but currently, 64-bit systems are predominant.If you want to obtain the byte size of a specific type in the computer through programming code, you can use the following code:
// Use sizeof operator to get the storage byte size of a specific type
#include <stdio.h>
int main() {
    printf("The storage byte size of int type is: %d", sizeof(int)); // Here, taking int type as an example
}Void TypeThe word void translates to “no value” in English, and the void type specifies that there is no available value. It is typically used in the following three cases:
| Index | Type and Description | 
|---|---|
| 1 | Function returns void There are various functions in C that do not return a value, or you could say they return void. The return type of a function that does not return a value is void. For example, void exit(int status); | 
| 2 | Function parameters are void There are various functions in C that do not accept any parameters. A function without parameters can accept a void. For example, int rand(void); | 
| 3 | Pointer points to void A pointer of type void* represents the address of an object, rather than a type. For example, the memory allocation function void *malloc(size_t size); returns a pointer to void, which can be cast to any data type. | 
Type Conversion
Type conversion, as the name suggests, is the process of converting a value of one data type to a value of another data type.
In C language, there are two types of type conversion (PS: Type conversion may also lead to loss of data precision or data truncation):
Implicit Type Conversion: Implicit type conversion occurs automatically in expressions without any explicit instructions or function calls. It usually involves automatically converting a smaller type to a larger type, such as converting int to long or float to double.
Explicit Type Conversion: Explicit type conversion requires the use of a cast operator, which can forcibly convert a value of one data type to another. Explicit type conversion allows programmers to have more precise control over data types when necessary.
Example of Implicit Type Conversion:
int i = 10;
float f = 3.14;
double d = i + f; // Implicit conversionExample of Explicit Type Conversion:
double d = 3.14159;
int i = (int)d; // Explicit conversionIn the next lesson, we will learn about variables in C language. Stay tuned! If you find this article helpful, please like and follow for support! ^-^