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

C++ beginner(2)- 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++,123,references,&&,variable
来源: https://www.cnblogs.com/francisforeverhappy/p/cpp_beginner2.html