当前位置:网站首页>C language - Introduction - Foundation - syntax - data type (4)
C language - Introduction - Foundation - syntax - data type (4)
2022-07-04 08:49:00 【Hu Anmin】
What is data ?
Dealing with data all the time in life
- for example : People's weight 、 height 、 income 、 Gender and other data
- In the process of using computers , Will also be exposed to a variety of data
- for example : Document data 、 Picture data 、 Video data, etc
data classification
Static data
- Static data refers to some permanent data , It's usually stored on a hard disk . The storage space of hard disk is generally large , Now the hard disk of ordinary computer has 500G about , Therefore, some large files can be stored in the hard disk
- The length of storage : Turn on the computer after it is turned off , The data is still there , As long as you don't take the initiative to delete or the hard disk is not broken , The data will always be
- Which are static data : Static data is usually stored on the hard disk in the form of files , Like documents 、 Photo 、 Video etc. .
Dynamic data
- Dynamic data refers to the process of running a program , Temporary data generated dynamically , Generally stored in memory . The memory space is generally small , Now the memory of ordinary computer is only 8G about , So use memory with caution , Don't occupy too much space
Storage space- The length of storage : After the computer is turned off , These temporary data will be cleared
- Which are dynamic data : When running a program ( Software ) when , The whole program will be loaded into memory , While the program is running , All kinds of temporary data are generated , These temporary data are stored in memory . When a program stops running or the computer is forced to shut down , All temporary data generated by this program will be cleared .
Since the hard disk has so much storage space , Why not load all the applications into the hard disk to execute ?
- The main reason is that the access speed of memory is faster than that of hard disk N times
- Conversion between static data and dynamic data , That is, load from disk to memory
- Conversion between dynamic data and static data , That is, save from memory to disk
As a programmer , What we care about most is the dynamic data in memory , Because the program we write runs in memory , All kinds of temporary data will be generated during the operation of the program , In order to facilitate the calculation and operation of data , C Language classifies these data , Provides a wealth of data types
Data type introduction
C The data types of languages are : Basic types 、 Empty type 、 Construct type and pointer type . The construction type includes the common body 、 Array 、 There are three types of structures . Basic types also include integers 、 floating-point 、 There are four types of characters and enumerations .
stay C In language , Numbers or Chinese characters that carry a series of information are data types , Computers cannot directly recognize different types , Therefore, when using a variable, you need to specify its data type in the declaration statement .C The data type of the language , Popular understanding is to put different items in different boxes , For example, decimals are stored in floating point 、 Integers are stored in integer 、 Characters are stored in character type and so on , Writing C The language needs to be different according to the stored data , Define different types of variables .
for example :int Integers are generally allocated 4 Bytes of storage space ,double Double precision floating-point allocation 8 Bytes of storage space ; The data type of a variable also determines what values the variable can take and what operations it can perform . For example, integer type can only be rounded , Decimal type can represent decimal , Integers and decimals can be added, subtracted, multiplied and divided .
Basic data type
C The most basic data type of a language is arithmetic , Including integer type and floating point number type . Character type 、 Enumeration types are also integer types in nature ; Integer type subdivides signed and unsigned integers 、 Long and short integers ; The difference between different integer types is that the storage length is different 、 The value range is different ; Floating point number type is relatively simple , It's all symbolic , It is divided into single precision and double precision floating-point numbers .
Integer types and declaration keywords include :
- Character type :
char
( Whether it is signed or unsigned is customized by the compiler ) - Signed character type :
signed char
- The unsigned character type :
unsigned char
- Signed short integers :
short
,signed short
,short int
,signed short int
- Unsigned short :
unsigned short
,unsigned short int
- signed int :
int
,signed
,signed int
- Unsigned integer :
unsigned
,unsigned int
- Signed long integer :
long
,signed long
,long int
,signed long int
- Unsigned long :
unsigned long
,unsigned long int
Floating point type declarations include :
- Single precision floating point :
float
- Double precision floating point :
double
- Long double precision floating point :
long double
Common basic data type size
char 1 byte ,int 4 byte , long 8 byte ,float 4 byte ,double 8 byte ;
Storage space size of each type , Number of bytes taken , It is related to the number of digits in the computer , Different machine data types have different sizes , Can pass sizeof() Keyword to calculate the size of each type , Determine the storage space and value range .
Get the variable size of the current machine
#include<stdio.h>
int main()
{
printf("int = %d\n",sizeof(int));
printf("short = %d\n",sizeof(short));
printf("long int = %d\n",sizeof(long int));
printf("long long int = %d\n",sizeof(long long int));
printf("char = %d\n",sizeof(char));
printf("_Bool = %d\n",sizeof(_Bool));
printf("float = %d\n",sizeof(float));
printf("double = %d\n",sizeof(double));
printf("long double = %d\n",sizeof(long double));
}
32 Bit compiler and 64 Bit compiler differences
32 Bit compiler
- char :1 Bytes
- char*( That is, pointer variable ): 4 Bytes (32 The addressing space of bits is 2^32, namely 32 individual bit, That is to say 4 Bytes )
- short int : 2 Bytes
- int: 4 Bytes
- unsigned int : 4 Bytes
- float: 4 Bytes
- double: 8 Bytes
- long: 4 Bytes
- long long: 8 Bytes
- unsigned long: 4 Bytes
64 Bit compiler ( At present, they are basically 64 Of course. )
- char :1 Bytes
- char*( That is, pointer variable ): 8 Bytes
- short int : 2 Bytes
- int: 4 Bytes
- unsigned int : 4 Bytes
- float: 4 Bytes
- double: 8 Bytes
- long: 8 Bytes
- long long: 8 Bytes
- unsigned long: 8 Bytes
边栏推荐
- [attack and defense world | WP] cat
- 2022 examination questions for safety managers of metal and nonmetal mines (underground mines) and examination papers for safety managers of metal and nonmetal mines (underground mines)
- What sparks can applet container technology collide with IOT
- How to send pictures to the server in the form of file stream through the upload control of antd
- DM8 command line installation and database creation
- How does Xiaobai buy a suitable notebook
- 小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
- Awk from entry to earth (15) awk executes external commands
- awk从入门到入土(6)正则匹配
- Codeforces Global Round 21(A-E)
猜你喜欢
How to re enable local connection when the network of laptop is disabled
DM8 command line installation and database creation
Developers really review CSDN question and answer function, and there are many improvements~
Educational Codeforces Round 119 (Rated for Div. 2)
Redis sentinel mechanism
Sequence model
How to choose solid state hard disk and mechanical hard disk in computer
ctfshow web255 web 256 web257
Snipaste convenient screenshot software, which can be copied on the screen
From scratch, use Jenkins to build and publish pipeline pipeline project
随机推荐
L1 regularization and L2 regularization
The map set type is stored in the form of key value pairs, and the iterative traversal is faster than the list set
ctfshow web255 web 256 web257
awk从入门到入土(18)gawk线上手册
Awk from entry to earth (8) array
ctfshow web255 web 256 web257
go-zero微服务实战系列(九、极致优化秒杀性能)
Getting started with microservices: gateway gateway
Flutter 集成 amap_flutter_location
How to solve the problem that computers often flash
4 small ways to make your Tiktok video clearer
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
DM8 uses different databases to archive and recover after multiple failures
From scratch, use Jenkins to build and publish pipeline pipeline project
埃氏筛+欧拉筛+区间筛
C语言-入门-基础-语法-[变量,常亮,作用域](五)
Industry depression has the advantages of industry depression
awk从入门到入土(9)循环语句
Awk from entry to earth (18) GAW K line manual
Redis sentinel mechanism