首页 > 编程语言 >C++ beginner(2)- variable

C++ beginner(2)- variable

时间:2022-08-17 00:12:09浏览次数:69  
标签:beginner int lvalue rvalue C++ references && variable

initialization

int x{}; // x is filled with zeroes, so x == 0
int x{123};
int x(123);
int a, b = 123, c{}, d{456}, e(789);
int* x, y, z; == int* x; int y; int z;
int *x, y, *z

Reference

C++ has two kinds of references: “lvalue” and “rvalue.” Just like with pointers, these are an annotation on another type:
we must initialize lvalue references and rvalue references when they are declared.

int a = 1;
// lvalue references
int& x = a;
int & x = a;
int &x =a;
 
// rvalue references
int&& x=a;
int && x=a;
int &&x=a;

标签:beginner,int,lvalue,rvalue,C++,references,&&,variable
From: https://www.cnblogs.com/francisforeverhappy/p/cpp_beginner2.html

相关文章

  • C++ 调整终端界面的大小
    #include<iostream>#include<string>#include<windows.h>#defineWIDTH40#defineHEIGHT15usingnamespacestd;voidinit(){//初始化终端界面char......
  • uec++ 1天
    用来让不是商店下载的ue进行注册        ufunction(exec)用来实现引擎中实现函数uclass staticclass 进行虚幻模拟反射机制 ......
  • C++primer练习13.55-58
    练习13.55为你的StrBlob添加一个右值引用版本的Push_backvoidStrBlob::push_back(string&&s){data->push_back(std::move(s));}练习13.56如果sorted定义如下,会发生......
  • AtCoder Beginner Contest 258
    A-When?问21:00后的第k分钟的时间#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+5;intn,a[N],cnt,k;int32_tmain(){ intn,h=21......
  • C++primer练习13.49-54
    练习13.49为你的String类添加一个移动构造函数和一个移动赋值运算符String(String&&a):elements(std::move(a.elements)),first_free(std::move(a.first_free)),cap(st......
  • c\c++实现天气数据获取
    #include<iostream>#include<WinSock2.h>#pragmacomment(lib,"ws2_32.lib")usingnamespacestd;constchar*host="api.seniverse.com";constchar*key="......
  • 基于C++的OpenGL 12 之多光源
    1.引言本文基于C++语言,描述OpenGL的多光源前置知识可参考:基于C++的OpenGL11之投光物-当时明月在曾照彩云归-博客园(cnblogs.com)笔者这里不过多描述每个名词......
  • 基于C++的OpenGL 11 之投光物
    1.引言本文基于C++语言,描述OpenGL的投光物前置知识可参考:基于C++的OpenGL10之光照贴图-当时明月在曾照彩云归-博客园(cnblogs.com)笔者这里不过多描述每个名......
  • C++版DNN最简主体框架
    附属代码:Matconvolution(Mat&delt,Mat&w,floatbias=0,intflp=0){Matdst;Matw_r180,delt_r180;switch(flp){case0://如果flp==0,只对w翻......
  • C++之运算符重载
    1运算符重载运算符  +  -  *  /  ++  --  %  &&  ->  >  <等classPerson{public: Person(){} Person(int......