当前位置:网站首页>C language - data type
C language - data type
2022-07-28 20:10:00 【Boring ~】
C Why does language specify data types ?
What is data type ?
Like in real life ,6 It's an integer ,6.6 It's a decimal ,a It's a letter .
This whole number , decimal , Letters describe a data , That is to say, this is the type of data , That's the data type .
stay C In language , We will write the code , There will also be data in the code , So in C How to describe data in language , There are also data types , stay C In language , We abstract data types from real life , We abstract integers into integers , Abstract decimals into floating point , Abstract letters into characters .
meanwhile , We subdivide the data types of integer and floating point , Divide integers into short integers , integer , Long integer , long long ; Floating point type is divided into single precision floating point type and double precision floating point type .
Why do data types have sizes ?
We write code in the compiler , Save it , Put it in memory , Memory is common to all things in a computer , Memory is like a computer warehouse , As a warehouse for storing computer things .
Let's write down a data , Data in computer , So we have to store it in the warehouse , Data should take up space , Therefore, it specifies how much space the data types describing data occupy in memory , There should be restrictions on everything stored in the warehouse , You can't deposit it casually .
Compare memory to a village warehouse , Villagers should store things inside , It should be stipulated , Such as storing grain , Can only occupy 1 Square meters of space , Etc., etc. .. There should be clear restrictions .
So an integer number can occupy in memory 4 Bytes of space .
A character type number can be used in memory 1 Bytes of space .
A short integer number can occupy in memory 2 Bytes of space
An integer number can occupy in memory 4 Bytes of space
A long integer number can occupy in memory 4 Bytes of space
A long integer number can be used in memory 8 Bytes of space
It is easy to understand that bytes are compared to rectangles , It is easy to understand that bits are compared to small lattices
A byte =8 A bit .
One binary number can be stored in one bit .
That is, a rectangle =8 A little lattice .
in other words , The space occupied by an integer number in memory can be stored 32 Bit binary number ,
So the maximum number that an integer number can represent is 2 Of 32 Bit binary number
Because integer , Character , Wait, these data types are the representatives of numbers .
They occupy different spaces in memory , So it can represent numbers of different sizes .
So use appropriate types to represent different numbers , It can save memory space .
Different types occupy different sizes of space , The size of the number that can be expressed is different , When storing data , Use appropriate data types , Space utilization will increase .
How to use data types ?
Enter... In the compiler 20,20 To store in memory , The data type used will be 20 To apply for space , Because the data type is qualified to apply , Because in C Language specifies that data types take up space , because C Language specifies how much space can be used for each data type . Why is the data type specified , Instead of the specified number ? Because the data type represents numbers , Is the representative of data , It describes numbers .
How data types are used ?
Data types are used to define variables , Define how much space the variable needs to request from memory , To store values . because C The language specifies how much space different data types can occupy , So when creating variables , Use data types to tell the compiler what it needs int Type space .
Let's say : Compare the data type to the type of room , Variables are compared to rooms , Worth comparing to guests , If you do not specify the type of room , Don't tell the guest how big the room is , What kind of , How do guests check in ?
边栏推荐
- A chip company fell in round B
- There is a 'single quotation mark' problem in the string when Oracle inserts data
- Codeignier framework implements restful API interface programming
- XOR operation and its usage
- Basic usage of docker
- Communication learning static routing across regional networks
- 中国能否在元宇宙的未来发展中取得突破,占领高地?
- The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
- [NPP installation plug-in]
- Information management system and games based on C language
猜你喜欢

The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced

9. Pointer of C language (5) how many bytes does the pointer variable occupy

Implementation of markdown editor in editor.md

KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书

Circular linked list OJ question
![最大交换[贪心思想&单调栈实现]](/img/ad/8f0914f23648f37e1d1ce69086fd2e.png)
最大交换[贪心思想&单调栈实现]

Multi-Modal Knowledge Graph Construction and Application: A Survey

How to write the SQL statement of time to date?

XOR operation and its usage
![[C language] Fibonacci sequence [recursion and iteration]](/img/02/6cff776db583f1b149686e15649d41.png)
[C language] Fibonacci sequence [recursion and iteration]
随机推荐
[C language] Pointer elementary knowledge points
[network] communication across regional networks learn how routing tables work
Prometheus deployment
C language functions and pointers
Deploy ZABBIX automatically with saltstack
JVM (24) -- performance monitoring and tuning (5) -- Analyzing GC logs
河北:稳粮扩豆助力粮油生产提质增效
MySQL command statement (personal summary)
Saltstack advanced
Common modules of saltstack
C+ + core programming
Edge detection and connection of image segmentation realized by MATLAB
The privatized instant messaging platform protects the security of enterprise mobile business
利用STM32的HAL库驱动1.54寸 TFT屏(240*240 ST7789V)
9. Pointer of C language (2) wild pointer, what is wild pointer, and the disadvantages of wild pointer
The cloud native programming challenge is hot, with 510000 bonus waiting for you to challenge!
English translation Portuguese - batch English conversion Portuguese - free translation and conversion of various languages
Tencent cloud deployment lamp_ Experience of building a station
Handan, Hebei: expand grassroots employment space and help college graduates obtain employment
C language array and bubble sort