当前位置:网站首页>New feature of C11 - Auto and decltype type type indicators
New feature of C11 - Auto and decltype type type indicators
2022-06-29 16:36:00 【Qiange】
1、auto Type specifier
(1)auto Is to let the compiler calculate the type of variable through the initial value , therefore auto A defined variable must have an initial value .
(2)auto You can declare multiple variables in one statement , The initial basic data type of multiple edges must be the same .
(3)auto Will ignore the top const, Keep the underlying const.
for example :
int i=0;
const int a=i;
auto b=a;// there b It's a int type ,a The top floor of const Features are ignored
auto c=&a;// there c Is a pointer to an integer constant , Therefore, the underlying const.( Addressing a constant object is a kind of bottom layer const)
(4) Set a type to auto references , The top level constant property in the initial value remains .
for example :
auto &d=a;//d Is a reference to an integer constant
2、decltype Type indicator
(1)decltype The type of variable to be defined can be inferred from the type of expression , So it is not necessary to initialize the variable with the value of the expression .
for example : The compiler does not need to call a function , Instead, you can determine the type of variable to be defined by the return type of the function .
(2) If decltype The expression used is a variable , be decltype Returns the type of the variable ( Including the top floor const And quote in ).
for example :
const int a=0,&b=a;
decltype(a) x = 0;//x The type is const int
decltype(b) y = x;//y The type is const int&
(3)decltype And references :
① If decltype The expression used is not a variable , that decltype Return the type corresponding to the expression result .
② If the content of an expression is a dereference operation , be decltype The result is a reference type .
as a result of : Dereference the pointer to get the object pointed to by the pointer , And you can assign values to this object , therefore decltype(*p) The result is int&, Instead of int.
for example :
int i=1,*p=&i,&r=i;
decltype(r+1) b;//b Is uninitialized int type
decltype(*p) c;//c yes int&, Must be initialized
③decltype If the expression is a variable with parentheses , The result will be to quote .
as a result of : Add brackets , The compiler will treat it as an expression , A variable is a special expression that can be used as an lvalue of an assignment statement , therefore In this way decltype You'll get the reference type .
for example :
decltype((i)) d;// Compilation error , because d yes int&, Must be initialized
decltype(i) e;//e Is an uninitialized int
边栏推荐
- C11新特性——auto、decltype类型指示符
- 自己实现一个ThreadLocal
- telnet+ftp 对设备进行 操控 和 升级
- 元数据管理Apache Atlas编译集成部署及测试
- Telnet+ftp to control and upgrade the equipment
- STM32 key chattering elimination -- Thinking of entry state machine
- Advanced MySQL - storage engine
- Basics | draw arcs in the physics engine
- C language -- printf print base prefix
- 为防止被00后整顿,一公司招聘要求员工不能起诉公司
猜你喜欢

同样是做测试,为什么别人年薪30W+?

Greedy Apple plans to raise the price of iphone14, which will provide opportunities for Chinese mobile phones

apache atlas断点查看

元数据管理Apache Atlas编译集成部署及测试

GNN笔记:消息传播模型

Stable currency risk profile: are usdt and usdc safe?

The third sprint of Wei long La Tiao: the growth rate of performance declined, and Liu Weiping and Liu Fuping cashed out in advance

Paper notes: e (n) equivariant graph neural networks

Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具

curl: (56) Recv failure: Connection reset by peer
随机推荐
【无标题】
Redolog and binlog
如何配置 logback?30分鐘讓你徹底學會代碼熬夜敲
Key wizard play monster learning - multi window and multi thread background judgment of character, pet blood volume and pet happiness
Basics | draw arcs in the physics engine
Advanced MySQL - storage engine
实战 | Change Detection And Batch Update
Which parameter is the partition information adjusted? The MySQL source stream API is used, not the table API
加速智能驾驶项目落地?你还缺一套真值测评系统
Flutter技术与实战(2)
Huaxia Fund: sharing of digital transformation practice achievements in the fund industry
Take another picture of cloud redis' improvement path
我,大厂测试员,降薪50%去国企,后悔了...
MySQL基础——事务
Why does selenium become the first choice for web automated testing? (source code attached)
南京大学:新时代数字化人才培养方案探讨
isEmpty 和 isBlank 的用法区别,居然一半的人答不上来?
【Proteus仿真】数码管递加/递减带闪烁消隐显示
Summary of common MySQL statements and commands
MySQL error: expression 1 of order by claim is not in group by claim and contains nonaggregated column