首页 > 代码库 > C++学习笔记5:如何给变量及函数命名?
C++学习笔记5:如何给变量及函数命名?
1.遵循C++规定的变量及函数命名方法;
2.原则:简单,易于理解;
以下是一些例子,可以作为参考:
//bad examples: int ccount;//Nobody knows what a ccount is. int i;//Generally bad unless use is trivial or temporary, such as loop variables. int _count;//don‘t start variable names with underscore. int data;//What kind of data? int value1,value2;//Can be hard to differentiate between the two? int x,y;//generally bad unless use is trivial, such as in trivial mathematical functions. //good examples: int customerCount;//clear what we‘re counting int index;//okay if obvious what we‘re indexing int totalScore;//good descriptive int numberOfApples;//descriptive int monstersKilled;//descriptive
C++学习笔记5:如何给变量及函数命名?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。