当前位置:网站首页>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 .
边栏推荐
- pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
- 指针进阶---指针数组,数组指针
- Upgrade tidb operator
- MySQL learning records 12jdbc operation transactions
- China dihydrolaurenol market forecast and investment strategy report (2022 Edition)
- 同一局域网的手机和电脑相互访问,IIS设置
- Research and investment forecast report of citronellol industry in China (2022 Edition)
- tree树的精准查询
- Leetcode skimming (5.29) hash table
- egg. JS directory structure
猜你喜欢
Let the bullets fly for a while
2022.02.13 - NC003. Design LRU cache structure
IoT -- 解读物联网四层架构
pytorch训练好的模型在加载和保存过程中的问题
【MySQL】鎖
PLT in Matplotlib tight_ layout()
[brush questions] top101 must be brushed in the interview of niuke.com
JS inheritance method
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
All the ArrayList knowledge you want to know is here
随机推荐
【Nvidia开发板】常见问题集 (不定时更新)
Yyds dry goods inventory three JS source code interpretation eventdispatcher
Migrate data from a tidb cluster to another tidb cluster
个人电脑好用必备软件(使用过)
C language custom type: struct
Grayscale upgrade tidb operator
[luatos-air551g] 6.2 repair: restart caused by line drawing
vulnhub hackme: 1
[research materials] 2021 live broadcast annual data report of e-commerce - Download attached
China polyether amine Market Forecast and investment strategy report (2022 Edition)
The mysqlbinlog command uses
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes
Online yaml to CSV tool
【MySQL】鎖
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
sys.argv
[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached
[research materials] 2021 China online high growth white paper - Download attached
LDAP Application Section (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