设为首页 加入收藏

TOP

2.2 Variables (7)
2013-10-07 16:15:47 来源: 作者: 【 】 浏览:82
Tags:2.2 Variables

2.2.3 Identifiers

Identifiers in C++(www.cppentry.com) can be composed of letters, digits, and the underscore character. The language imposes no limit on name length. Identifiers must begin with either a letter or an underscore. Identifiers are case-sensitive; upper- and lowercase letters are distinct:

  1. // defines four different int variables   
  2. Int somename, someName, SomeName, SOMENAME;  

The language reserves a set of names, listed in Tables 2.3 and Table 2.4, for its own use. These names may not be used as identifiers.

The standard also reserves a set of names for use in the standard library. The identifiers we define in our own programs may not contain two consecutive underscores, nor can an identifier begin with an underscore followed immediately by an uppercase letter. In addition, identifiers defined outside a function may not begin with an underscore.

Conventions for Variable Names

There are a number of generally accepted conventions for naming variables. Following these conventions can improve the readability of a program.


.. An identifier should give some indication of its meaning.

.. Variable names normally are lowercase—index, not Index or INDEX.

.. Like Sales_item, classes we define usually begin with an uppercase letter.

.. Identifiers with multiple words should visually distinguish each word, for

example, student_loan or studentLoan, not studentloan.

Naming conventions are most useful when followed consistently.

Table 2.3: C++(www.cppentry.com) Keywords

Table 2.4: C++(www.cppentry.com) Alternative Operator Names

EXERCISES SECTION 2.2.3

Exercise 2.12: Which, if any, of the following names are invalid

(a) int double = 3.14;

(b) int _;

(c) int catch-22;

(d) int 1_or_2 = 1;

(e) double Double = 3.14;

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇DEFINED TERMS (3) 下一篇2.2 Variables (9)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)