当前位置:网站首页>Compound Types--references, pointers
Compound Types--references, pointers
2022-07-30 04:45:00 【Well worth the trip - Rui】
Composite type:
Types defined based on other types (int * p int &d)
A declaration statement consists of a basic data type (base type) followed by a list of declarators. Each declarator names a variable andSpecifies this variable is of a type relative to the basic data type.
Cite:
Another alias for the object
#include using namespace std;int main(){int val = 1024;int &refval = val; //refval and val point to the same address refval is another name for valcout << &val << " " << &refval << endl;int &ival; //Error: reference must be initializedcout << val << " " << refval << endl;return 0;} General initialization, yesCopy the initial value to the newly created objectin, while reference initialization
Not a copy, a reference cannot be rebound to another object and must be initialized
- A reference is not an object, just another alias for an existing object
- Operations on references are operations on objects bound to references
- A reference is not an object so a reference to a reference cannot be defined (int&(&a))
int main(){int val = 1024;int&refval = val;refval = 2048;cout << refval << " " << val << endl;return 0;}
I will not talk about it when I go to practice.
Pointer
A pointer is an address
The declarator is written in the form of *d
int* ip1, *ip2;//ip1 and ip2 are both pointers to int objectsdouble* dp, dp1;//dp is a pointer to a double type object, dp1 is a double type objectGet object address
The pointer stores the address of an object. To get the address of the object, you need to get the address character&
int val = 42;int* p = &val;//p stores the address of val,//p points to a pointer to the variable valNote:A reference is not an object and cannot take an address, but a pointer is an object that has a pointer reference
Difference between reference and pointer
- The reference must be initialized, the pointer must not be initialized, it will get a random value
- A reference cannot rebind an object, while a pointer can be given any object of the same type at any time
- A reference is not an object, so a reference to a reference cannot be defined, while a pointer can define a secondary pointer
- The size of the reference is the size of the reference type, and the pointer is always the number of bytes occupied by the address space
边栏推荐
- Thinkphp 5.0.24 Variable Override Vulnerability Causes RCE Analysis
- 山西省第二届网络安全技能大赛(企业组)部分赛题WP(十)
- 七、自定义配置
- VUX Datetime 组件compute-days-function动态设置日期列表
- 动态规划问题(完结篇)
- Dynamic Programming Problems (End)
- See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices
- WPF introduces ttf icon file usage record
- String problem (below)
- 2.6基数排序(桶排序)
猜你喜欢

复现XXL-JOB 任务调度中心后台任意命令执行漏洞

Image stitching (registration) case based on OpenCV

Shanxi group (enterprises) in the second network security skills competition part problem WP (7)

Solve the error SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xb7 in position 0: invalid start b
![[MRCTF2020]Hello_ misc](/img/ea/0faacf6e544b60e3459d8ace4d5f42.png)
[MRCTF2020]Hello_ misc

Dynamic Programming Problems (End)

Introduction to database - MySQL simple introduction

Thinkphp 5.0.24 Variable Override Vulnerability Causes RCE Analysis
![[Redis Master Cultivation Road] Jedis - the basic use of Jedis](/img/e3/0c6efd03432a01f857796f0bf648ef.png)
[Redis Master Cultivation Road] Jedis - the basic use of Jedis

mysql隔离级别
随机推荐
2.4希尔排序
共建共享数字世界的根:阿里云打造全面的云原生开源生态
WPF introduces ttf icon file usage record
双指针问题(上)
【软件工程之美 - 专栏笔记】31 | 软件测试要为产品质量负责吗?
WPF study notes "WPF Layout Basics"
全流程调度——Azkaban入门与进阶
The Azure developer news 丨 memorabilia in July
Shi Xingguo, founder of Hyperchain, was interviewed by 21st Century Business Herald to interpret Shanghai's new NFT regulations and digital development
Database Design of Commodity Management System--SQL Server
Simple experiment with BGP
Golang eight-legged text finishing (continuous handling)
Six, read application configuration + log configuration
KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
WPF recursively obtains the list of specified control types in the form
SaaS多租户数据隔离的三种解决方案
解决报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start b
七、自定义配置
VUX Datetime 组件compute-days-function动态设置日期列表
Classification of decision tree classification