当前位置:网站首页>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
边栏推荐
- Shanxi group (enterprises) in the second network security skills competition part problem WP (8)
- Requirements design document and the changing role of the product manager
- Android Studio implements login registration - source code (connecting to MySql database)
- Simulation Problem (Part 1)
- 深圳见!云原生加速应用构建专场:来看云原生 FinOps、SRE、高性能计算场景最佳实践
- 1. 获取数据-requests.get()
- 模拟问题(上)
- POJ1321 棋盘问题(详解)
- 模拟问题(中)
- 2.4 hill sorting
猜你喜欢

Simple experiment with BGP

sql statement - how to query data in another table based on the data in one table

Usage of EFR32 as sniffer for Zigbee/Thread

cnpm installation steps
Go 学习笔记(84)— Go 项目目录结构

Discourse 自定义头部链接(Custom Header Links)

2.4希尔排序

1. Get data - requests.get()

MYSQL unique constraint
Go study notes (84) - Go project directory structure
随机推荐
WPF recursively obtains the list of specified control types in the form
【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
山西省第二届网络安全技能大赛(企业组)部分赛题WP(八)
4. Web Development
Simulation problem (middle)
(Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
【MySQL系列】-B+树索引和HASH索引有什么区别
Chapter8 支持向量机
GCC Rust获批将被纳入主线代码库,或将于GCC 13中与大家见面
webService interface
双指针问题(中)
Seven, custom configuration
Learning of redis_Basic part
Become a qualified cybersecurity, do you know this?
Unity beginner 5 cameras follow, border control and simple particle control (2 d)
Introduction to database - MySQL simple introduction
Go study notes (84) - Go project directory structure
复现XXL-JOB 任务调度中心后台任意命令执行漏洞
MNIST of Dataset: MNIST (handwritten digital image recognition + ubyte.gz file) data set introduction, download, usage (including data enhancement) detailed guide