当前位置:网站首页>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 ?
边栏推荐
- Idea properties file display \u solution of not displaying Chinese
- [C language] string reverse order implementation (recursion and iteration)
- [NPP installation plug-in]
- 9. Pointer of C language (1) what is pointer and how to define pointer variables
- [C language] print pattern summary
- Advanced notes (Part 2)
- 5. Difference between break and continue (easy to understand version)
- 通配符 SSL/TLS 证书
- The privatized instant messaging platform protects the security of enterprise mobile business
- Basic knowledge of communication network 01
猜你喜欢

3、 Are formal and actual parameters in a programming language variables?

C+ + core programming
![[C language] simulation implementation of strlen (recursive and non recursive)](/img/73/e92fe714515491f1ea366d6924c9ec.png)
[C language] simulation implementation of strlen (recursive and non recursive)

软考中级(系统集成项目管理工程师)高频考点
![[C language] random number generation and `include < time. H > 'learning](/img/bb/3e47bf2e3b25653d9048884d65cda3.png)
[C language] random number generation and `include < time. H > 'learning

Know small and medium LAN WLAN
![[C language] function](/img/81/c185e2bb5eccc13433483f9558f52a.png)
[C language] function
![[NPP installation plug-in]](/img/6f/97e53116ec4ebc6a6338d125ddad8b.png)
[NPP installation plug-in]

Item exception handling in SSM

Leetcode Day1 score ranking
随机推荐
C language operators and input and output
Communication learning static routing across regional networks
Design of air combat game based on qtgui image interface
English translation Arabic - batch English translation Arabic tools free of charge
Special draft of Mir | common sense knowledge and reasoning: representation, acquisition and application (deadline on October 31)
Netcoreapi operation excel table
跨区域网络的通信学习静态路由
Leetcode day4 the highest paid employee in the Department
Know small and medium LAN WLAN
Zfoo adds routes similar to mydog
[C language] function
Can China make a breakthrough in the future development of the meta universe and occupy the highland?
Sequential linear table - practice in class
[C language] guessing numbers game [function]
爬取IP
Information management system and games based on C language
flask_ Mail source code error
Deploy LNMP automatically with saltstack
Common APIs in string
Solve flask integration_ Error reporting in restplus