c++标识符


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。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM