当前位置:网站首页>02-3. Difference between pointer and reference
02-3. Difference between pointer and reference
2022-07-19 11:31:00 【The streets of Leningrad】
Preface : This article is mainly used for personal review , Pursue simplicity , Thank you for your reference 、 Communication and handling , It may be revised and improved in the future .
Because it's a personal review , There will be partial compression and omission .
The difference between pointer and reference
int main()
{
int a = 10;
int& ra = a;// In grammar , Here to a This space has taken an alias , There is no new space
ra = 20;
int* pa = &a;// In grammar , Here's a definition pa Pointer to the variable , opened 4 Byte store a The address of
*pa = 20;
return 0;
}Actually, from the perspective of assembly implementation , The underlying layer of the reference is also handled in a similar way to the pointer address

When using references and pointers , The difference between them :
1. Reference conceptually defines the alias of a variable , The pointer stores a variable address .
2. Reference redefinition must initialize , Pointer not required .
3. Reference refers to an entity during initialization , You can't refer to other entities , And the pointer can point to any entity of the same type at any time .
4. No, NULL quote , But there are NULL The pointer .
5. stay sizeof Different meanings in : The reference result is the size of the reference type , But the pointer is always the number of bytes in the address space .
6. Reference self add refers to the addition of referenced entities 1, Pointer self addition means that the pointer is offset backward by a type of size
7. With multi-level pointer , But there is no multi-level reference .
8. Different ways to access entities , The pointer needs to show dereference , References are handled by the compiler itself
9. References are relatively safer to use than pointers
边栏推荐
- Automated graphical interface library pyautogui
- A curated list of awesome Qt and QML
- 委派雙親之類加載器
- pjudge#21652-[PR #4]到底有没有九【数位dp】
- Set the interface language of CMD command prompt window to English
- Robot development -- robot data summary
- Deep learning for generic object detection: a survey
- Leetcode 1304. 和为零的 N 个不同整数
- The concept of data guard broker and the configuration process of data guard broker
- From "passive" to "active", how can zeta technology help to upgrade "rfid2.0"?
猜你喜欢

02-3、指针和引用的区别

Introduction to common distributed locks

Mysql 自增id、uuid与雪花id

Unity3d read mpu9250 example source code

Introduction of database lock, shared with InnoDB, exclusive lock

A fastandrobust convolutionalneuralnetwork-based defect detection model inproductqualitycontrol-閱讀筆記

Getting started with web security - deploy snort open source ids/ips system

Discussion on Euler angle solution of rocket large maneuvering motion

The type of MySQL index (single column index, combined index, BTREE index, clustered index, etc.)

传输层 -------- TCP(一)
随机推荐
PPDE第二季度迎新 | 欢迎22位AI开发者加入飞桨开发者技术专家计划!
今日睡眠质量记录79分
Leetcode 1328. 破坏回文串(可以,已解决)
Four methods of traversing key value in map
Play with the one-stop scheme of cann target detection and recognition
E-commerce sales data analysis and prediction (date data statistics, daily statistics, monthly statistics)
466-82(3、146、215)
function/symbol ‘pango_context_set_round_glyph_positions‘ not found in library ‘libpango-1.0.so.0‘x
Download of common getshell tools
虚拟化排错概论
玩转CANN目标检测与识别一站式方案
Daily question brushing record (26)
《MySQL DBA封神打怪之路》专栏学习大纲
Detailed explanation of multiple linear regression
Performance optimization @contented to reduce pseudo sharing
SPI service discovery mechanism
Second classification learning is extended to multi classification learning
夢想CMS 前臺搜索SQL注入
02-3、指针和引用的区别
Delegate parents and other loaders