当前位置:网站首页>[dish of learning notes, dog learning C] getting to know the pointer for the first time
[dish of learning notes, dog learning C] getting to know the pointer for the first time
2022-07-21 03:14:00 【Jiang Junzhu】
List of articles
One 、 Memory
1. Memory unit
In order to use memory effectively , Divide the memory into small ones Memory unit
; In order to effectively access each unit , The memory unit is numbered , These numbers are called The address of the memory unit
.
2. Memory address
What we often say 32 Bit and 64 Position refers to 32 or 64 Root address line , The address line is a physical line , It's actually a wire that can be energized , The positive charge is 1 Negatively charged 0
;
Convert electrical signals into digital information , You can get a set of 0、1 Binary number of components ;
stay 32 In the middle of the plane , We put 32 All the electrical signals generated by the root address line are listed , You can get 232 Group binary number , We call these binary numbers memory numbers , And these binary numbers are what we call Memory address
;
Each address corresponds to a memory unit , The size of a memory unit is one byte .
Two 、 The pointer
1. Pointer to the variable
The address number of memory is actually a value , You also need space to store , Pointer variables are used to store address numbers , Simply put, a pointer is an address .
Pointers are typed , The way we declare a pointer variable is data type * Pointer name
, among data type
It explains what type of object this pointer executes ,*
This indicates that this is a pointer variable .
int main() {
//a Space is allocated in memory - 4 byte
int a = 10;
// Define a pointer variable pa, And will a Address assigned to pa
//* explain pa It's a pointer variable
//int explain pa The object of execution is int Type of
int* pa = &a;
//& It's a monocular operator , Used to get the address
//%p Specifically for printing addresses
printf("a The address is %p\n", &a);
//* Dereference operation , *pa It is through pa Address inside , find a
*pa = 20;
printf("a Value :%d", a);
return 0;
}
1. Pointer size
We said that the pointer is the address , And the essence of address is a value , Then this value also needs to be stored , In other words, pointer variables also need memory space to store , How big is a pointer ?
// Pointer size
int main() {
printf("%d\n", sizeof(int*));//4
printf("%d\n", sizeof(char*));//4
printf("%d\n", sizeof(long*));//4
printf("%d\n", sizeof(long long*));//4
printf("%d\n", sizeof(double*));//4
printf("%d\n", sizeof(float*));//4
printf("%d\n", sizeof(short*));//4
}
How much space does the pointer occupy , It depends on how much space is needed to store the address , And the address is actually a string of binary numbers , So no matter what type of pointer , It's the same size ;
How big is the pointer ? In fact, it's not hard to get out , The length of each binary number is actually determined by the number of address lines ,32 The address line of the bit machine has 32 root , Each address line corresponds to a binary number , therefore 32 The binary number length of bit machine is 32, be 32 The size of the bit machine pointer is 4 byte
. Empathy ,64 Bit machines are 8 Bytes
.
【 Learning notes Dog learn C】 Initial order of pointer
【 Learning notes Dog learn C】 Advanced pointer
边栏推荐
- [scientific literature measurement] keyword mining and visualization
- SQL optimization (x): association update
- Learn about spark project on nebulagraph
- 【学习笔记之菜Dog学C】详解数组名
- Apache Doris ODBC appearance database mainstream version and its ODBC version correspondence
- 2022-7-19 第八小组 顾宇佳 学习笔记 (this关键字和封装)
- Rpc:thrift framework
- Oracle按中文排序
- Vben admin time selector related configuration and setting of unselectable time
- 请问一下老师们,flink SQL kafka connector中的startup mode 选择
猜你喜欢
随机推荐
蓝桥杯2020年第十一届国赛真题-天干地支
记录一次C# 使用FFmempeg提取音频文件
Websocket server code protocol analysis, learn to do their own protocol ideas.
Apache Doris rapid deployment operation and maintenance guide based on ansible
Graduation season -- use technology of various application scenarios
Transform streams into data products
SIGIR‘22 推荐系统论文之对比学习篇
2022-7-19 Gu Yujia's learning notes of group 8 (this keyword and packaging)
Apache Doris connects to SQL server through ODBC
ES6中Symbol、迭代器和生成器基本语法
mknod命令:创建设备文件
[scientific literature measurement] keyword mining and visualization
LabVIEW中的自动保存功能
Oracle按中文排序
试题 C: 刷题统计
RPC:Thrift框架
Excuse me, teachers, how to choose the startup mode in the flynk SQL Kafka connector
B. Difference of GCDs
Apache Doris binlog Load use Methods and Examples
[scientific literature measurement] statistics and visualization of word number and frequency of Chinese and English literature titles and abstracts