Linux C++ 变量

在前面的代码中我们使用了这样的一条语句:

cout << "Hello,Linux C++!" << endl;
复制代码

其中 "Hello,Linux C++!" 在我们看来就是一堆字符和符号。但是这么一句我们还可以接受,毕竟就写了一次吗,如果我们需要写这样类似的语句上千行,想想都头大。

我们每个人都有自己的名字,为了什么,辨识度高一点,更加方便一点。同样的在程序中我们也给这些奇奇怪怪的东西都起个名字,就像我们都是人类一样,它们就都是变量。

这里我们打个比方:

 它  是    动物
 程序代码:
 a    =    "animal";
复制代码

这里a就是一个变量,复杂的我们不管,这里我们就说通俗的,变量就是一个类似名字的东西。

起名字还是很有讲究的,在c++中起名字也不能乱来的。下面这些名字我们不能用:

lignas (C++11 起)
alignof (C++11 起)
and
and_eq
asm
atomic_cancel (TM TS)
atomic_commit (TM TS)
atomic_noexcept (TM TS)
auto(1)
bitand
bitor
bool
break
case
catch
char
char8_t (C++20 起)
char16_t (C++11 起)
char32_t (C++11 起)
class(1)
compl
concept (C++20 起)
const
consteval (C++20 起)
constexpr (C++11 起)
const_cast
continue
co_await (协程 TS)
co_return (协程 TS)
co_yield (协程 TS)
decltype (C++11 起)
default(1)
delete(1)
do
double
dynamic_cast
else
enum
explicit
export(1)
extern(1)
false
float
for
friend
goto
if
import (模块 TS)
inline(1)
int
long
module (模块 TS)
mutable(1)
namespace
new
noexcept (C++11 起)
not
not_eq
nullptr (C++11 起)
operator
or
or_eq
private
protected
public
reflexpr (反射 TS)
register(2)
reinterpret_cast
requires (C++20 起)
return
short
signed
sizeof(1)
static
static_assert (C++11 起)
static_cast
struct(1)
switch
synchronized (TM TS)
template
this
thread_local (C++11 起)
throw
true
try
typedef
typeid
typename
union
unsigned
using(1)
virtual
void
volatile
wchar_t
while
xor
复制代码
 and 、 bitor 、 or 、 xor 、 compl 、 bitand 、 and_eq 、 or_eq 、 xor_eq 、 
 not 及 not_eq (还有双标符 <% 、 %> 、 <: 、 :> 、 %: 及 %:%:)提供表示标准记号的替用方法。
 所以这些特殊词用的时候还得慎重。

特殊含义的标识符
override (C++11)
final (C++11)
audit (C++20)
axiom (C++20)
transaction_safe (TM TS)
transaction_safe_dynamic (TM TS)
复制代码

我们起名字要遵守下面的交通规则:

有效标识(变量,函数等名字)有字母,数字和下划线(_)组成。并且开头不能是数字,其中_可以作为开头,不过一般是给外部链接用的。
复制代码

在c++中大小写是敏感的,比如 a和A是不同的。 合法名字大概长这个样子:

int number = 0;
int studentNumbers = 100;
int school_numbers = 30;
int school_numbers_001 = 1;
int school_numbers001 = 1;
复制代码

转载于:https://juejin.im/post/5ca5e24ce51d45486e6925e4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值