HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
In the C language, data type refers to a wide range of systems for variable or function declaration different types. Type of the variable determines the variable storage space occupied, and how to interpret the stored bit patterns.
C can be divided into the following categories:
序号 | 类型与描述 |
---|---|
1 | 基本类型: 它们是算术类型,包括两种类型:整数类型和浮点类型。 |
2 | 枚举类型: 它们也是算术类型,被用来定义在程序中只能赋予其一定的离散整数值的变量。 |
3 | void 类型: 类型说明符void表明没有可用的值。 |
4 | 派生类型: 它们包括:指针类型、数组类型、结构类型、共用体类型和函数类型。 |
Array type and structure of the type referred to as aggregate types. Type of the function refers to the type of function return values. In the next section of this chapter we will introduce the basic type, other types will explain in the back a few chapters.
The following table lists the details about the standard integer types of storage sizes and value ranges:
类型 | 存储大小 | 值范围 |
---|---|---|
char | 1 字节 | -128 到 127 或 0 到 255 |
unsigned char | 1 字节 | 0 到 255 |
signed char | 1 字节 | -128 到 127 |
int | 2 或 4 字节 | -32,768 到 32,767 或 -2,147,483,648 到 2,147,483,647 |
unsigned int | 2 或 4 字节 | 0 到 65,535 或 0 到 4,294,967,295 |
short | 2 字节 | -32,768 到 32,767 |
unsigned short | 2 字节 | 0 到 65,535 |
long | 4 字节 | -2,147,483,648 到 2,147,483,647 |
unsigned long | 4 字节 | 0 到 4,294,967,295 |
Note that the size of the various types of storage systems related to the number of bits, but a 64-bit general-purpose system based.
Here are the differences between 32-bit and 64-bit system memory size (windows the same):
In order to obtain a type of a variable or the exact size on a particular platform, you can use thesizeof operator.Expressionsizeof (type)to give an object or type of storage bytes. The following example demonstrates Get int type size:
#include <stdio.h> #include <limits.h> int main() { printf("int 存储大小 : %lu \n", sizeof(int)); return 0; }
When you compile in Linux and execute the above program, it will produce the following results:
int 存储大小 : 4
The following table lists the details about the standard floating-point type storage size, value range and precision:
类型 | 存储大小 | 值范围 | 精度 |
---|---|---|---|
float | 4 字节 | 1.2E-38 到 3.4E+38 | 6 位小数 |
double | 8 字节 | 2.3E-308 到 1.7E+308 | 15 位小数 |
long double | 16 字节 | 3.4E-4932 到 1.1E+4932 | 19 位小数 |
Float.h header file defines macros can be used in the program and other relevant details of the values of real numbers represented in binary. The following examples will output a floating-point type storage space as well as its range of values:
#include <stdio.h> #include <float.h> int main() { printf("float 存储最大字节数 : %lu \n", sizeof(float)); printf("float 最小值: %E\n", FLT_MIN ); printf("float 最大值: %E\n", FLT_MAX ); printf("精度值: %d\n", FLT_DIG ); return 0; }
When you compile in Linux and execute the above program, it will produce the following results:
float 存储最大字节数 : 4 float 最小值: 1.175494E-38 float 最大值: 3.402823E+38 精度值: 6
void type specified value is not available. It is typically used in the following three cases:
序号 | 类型与描述 |
---|---|
1 | 函数返回为空 C 中有各种函数都不返回值,或者您可以说它们返回空。不返回值的函数的返回类型为空。例如void exit (int status); |
2 | 函数参数为空 C 中有各种函数不接受任何参数。不带参数的函数可以接受一个 void。例如int rand(void); |
3 | 指针指向 void 类型为 void * 的指针代表对象的地址,而不是类型。例如,内存分配函数void *malloc( size_t size );返回指向 void 的指针,可以转换为任何数据类型。 |
Now if you still can not fully understand the void type, do not worry too much, in the subsequent sections we will elaborate on these concepts.