随笔 - 21, 文章 - 2, 评论 - 2, 阅读 - 7691

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

c++标识符

Posted on   抑或  阅读(1462)  评论(0编辑  收藏  举报

c++的标识符由字母、数字和下画线组成,其中必须以字母或下画线开头。标识符的长度没有限制,但是对大小写字母敏感。

下表,c++保留了一些名字供语言本身使用,这些名字不能被用作标识符。

c++关键字
alignas continue friend register true
alignof decltype goto -reinterpret_cast try
asm default if return typedef
auto delete inline short typeid
bool do int signed typename
break double long sizeof union
case dynamic_cast mutable static unsigned
catch else namespace static_assert using
char enum new static_cast virtual
char_16t explicit noexcept struct void
char_32t export nullptr switch volatile
class extern operator template wchar_t
const false private this while
constexpr float protected thread_local  
const_cast for public throw  
c++操作符替代名
and bitand compl not_eq or_eq xor_eq
and_eq bitor not or xor  

同时c++也为标准库保留了一些名字。用户自定义的标识符中不能连续出现两个下画线,也不能以下画线紧连大写字母开头。此外,定义在函数体外的标识符不能以下画线开头。

变量命名规范:变量命名有许多约定俗成的规范:

1.标识符要能体现实际含义。

2.变量名一般用小写字母,如index,不要用Index或INDEX。

3.用户自定义的类名一般以大写字母开头,如Sales_item。

4+如果标识符以多个单词组成,则单词间应有明显区分,如student_loan或studentLoan。

努力加载评论中...
1
点击右上角即可分享
微信分享提示