当前位置:网站首页>Deep analysis of C language data storage in memory
Deep analysis of C language data storage in memory
2022-07-06 08:32:00 【Finally - null】
author : In the end —NULL
motto : Make a little progress every day , Persistence makes a big difference !
Article content : C Storage of language data in memory .
Preface :
After a period of study, we have learned that in C Language contains various data , But do we really understand the meaning of type , And how different data types are stored in memory . Next, we will dissect one by one .
Catalog
1. A detailed description of data types :
3. Storage of different data types in memory
2. The storage form of data in memory :
3. Storage order of data in memory :
2. Judge the big and small ends :
4.char Type of data stored in memory
1. A signed char Store data range in memory :
2. Unsigned char Store data range in memory :
5. Storage rules of floating point numbers in memory
1. Floating point storage rules :
2. Rules for storing floating-point numbers in memory
1. A detailed description of data types :
1. Plastic surgery Family
char
unsigned char
signed char
short
unsigned short [int]
signed short [int]
int
unsigned int
signed int
long
unsigned long [int]
signed long [int]
2. Floating point family
float
double
3. Construction type
> An array type
> Type of structure struct
> Enumeration type enum
> Joint type union
4. Pointer types
int *pi;
char *pc;
float* pf;
void* pv;
5. Empty type
void
2. The meaning of type
1. Different data types determine how much memory space we apply for in memory when defining variables .
2. Different data types determine the form in which we store data in the open space
3. Storage of different data types in memory
1. Concept introduction :
Data is stored in binary form in the computer : There are three representations , namely Original code , Inverse code , Complement code .
The three representations have corresponding sign bits : highest ‘0’ It means a positive number , highest ‘1’ A negative number
Three different representation rules :
Original code : Write it directly according to the corresponding binary bit
Inverse code : The sign bits remain the same , The other bits are reversed bit by bitComplement code : Add one to the inverse code to get the complement
2. The storage form of data in memory :
int a= - 10;
summary : Through debugging, it is found that the data is stored in the form of complement in memory .
3. Storage order of data in memory :
1. Large and small end :
The phenomenon :
Why is the data we define opposite to the data stored in memory ?
Big end storage : Low byte order ( Low weight bit ) The data of is stored at a high address , High byte order ( High weight bit ) The data of is stored at the low address .
Small end storage : Low byte order ( Low weight bit ) The data of is stored at the low address , High byte order ( High weight bit ) The data of is stored at a high address .
Whether to use big end storage or small end storage for storing data depends on the compiler . stay VS Small end storage .
2. Judge the big and small ends :
Title Description : Write a piece of code , Determine whether the compiler used is small end storage or large end storage .
Ideas : Shaping data 1 Forced to char type , Then apply the solution
#include<stdio.h> int check_sys() { int i = 1; return *(char*)&i; } int main() { if (check_sys()) { printf(" The small end \n"); } else { printf(" Big end \n"); } return 0; }
4.char Type of data stored in memory
char
signed char ; // The signed
unsigned char;// Unsigned
1. A signed char Store data range in memory :
summary : The signed char The data storage range of type is -128~127
2. nothing Symbol char Store data range in memory :
summary : The storage range of unsigned data in memory is 0~255
5. Storage rules of floating point numbers in memory
1. Floating point storage rules :
According to international standards IEEE( Institute of electrical and Electronic Engineering ) 754, Any binary floating point number V It can be expressed in the following form :
(-1)^S * M * 2^E
(-1)^S The sign bit , When S=0,V Is a positive number ; When S=1,V It's a negative number .
M Represents a significant number , Greater than or equal to 1, Less than 2.
2^E Indicates the index bit .
give an example :
5.5
Binary form :101.1
Scientific enumeration :1.011*2^2
Add sign bits :(-1)^0*1.011*2^2
0==S M==1.001 E==2
2. Rules for storing floating-point numbers in memory
1.32 Bit single precision floating point number :
highest 1 Bits are sign bits S, And then there was 8 Bit index E, The rest M yes 23 Significant digits ( Does not include 1, In order to improve the accuracy ).
2.64 Bit double progress floating-point number :
highest 1 Bits are sign bits S, And then there was 11 Bit index E, The rest M yes 52 Significant digits ( Does not include 1, In order to improve the accuracy ).
Index E Storage rules for :
E Is an unsigned number , therefore E by 8 position , The scope is 0~255, If E by 11 position , The scope is 0~2047.
But because floating-point numbers are negative , So when storing single precision floating-point numbers, add 127, Double precision floating-point number plus 1023
3. Rules for fetching floating-point numbers from memory
1.E Not all for 0 Or not all of them 1:
Index E The value of minus 127(1023), Add 1.
2.E All for 0:
Floating point E be equal to 1-127 perhaps (1-1023) That's the true value .
The significant number is not preceded by 1, It's reduced to 0.xxxxx Decimals of , This is to indicate positive and negative 0, And close to 0 A very small number of .
3.E All for 1:
At this time , If the significant number M All for 0, Express ± infinity ( It depends on the sign bit s);
4. give an example :
#include<stdio.h> int main() { int n = 9; float *pFloat = (float *)&n; printf("n The value of is :%d\n",n); printf("*pFloat The value of is :%f\n",*pFloat); *pFloat = 9.0; printf("num The value of is :%d\n",n); printf("*pFloat The value of is :%f\n",*pFloat); return 0; }Code interpretation :
![]()
6. summary
The above is about the storage rules of integer data and floating-point numbers in memory . I hope it helped you , If there are errors and deficiencies in the middle content, please leave a comment .
边栏推荐
- [luatos-air551g] 6.2 repair: restart caused by line drawing
- 生成器参数传入参数
- pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
- ESP系列引脚說明圖匯總
- Erc20 token agreement
- 2. File operation - write
- 深度剖析C语言指针
- Upgrade tidb operator
- egg. JS project deployment online server
- Image fusion -- challenges, opportunities and Countermeasures
猜你喜欢

JVM 快速入门

pytorch训练好的模型在加载和保存过程中的问题

sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题

PLT in Matplotlib tight_ layout()

All the ArrayList knowledge you want to know is here

2022.02.13 - NC002. sort

Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform

生成器参数传入参数

3. File operation 3-with

IoT -- 解读物联网四层架构
随机推荐
sys. argv
LDAP application (4) Jenkins access
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
【MySQL】日志
VMware 虚拟化集群
移位运算符
Verrouillage [MySQL]
[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]
China vanadium battery Market Research and future prospects report (2022 Edition)
sublime text中conda环境中plt.show无法弹出显示图片的问题
synchronized 解决共享带来的问题
Day29-t77 & t1726-2022-02-13-don't answer by yourself
Research Report on Market Research and investment strategy of microcrystalline graphite materials in China (2022 Edition)
Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)
Modify the video name from the name mapping relationship in the table
[research materials] 2021 China online high growth white paper - Download attached
Summary of MySQL index failure scenarios
pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
2022.02.13 - NC001. Reverse linked list
Image,cv2读取图片的numpy数组的转换和尺寸resize变化










