What are the naming rules for C++ identifiers?

The naming rules for C++ identifiers are as follows:

  1. It can only consist of letters (a-z, A-Z), numbers (0-9), and underscores (_).
  2. It must start with a letter or an underscore, and cannot start with a number.
  3. Differentiate between uppercase and lowercase, the identifiers “abc” and “ABC” are not the same.
  4. Do not use C++ keywords as identifiers, such as “int” or “for”.
  5. There is no limit on the length of identifiers, but it is recommended not to exceed 255 characters.
  6. Follow certain naming conventions, such as using meaningful names, lowercase letters, and camel case.

Here are some examples of identifiers that adhere to C++ naming conventions:

  1. myVariable
  2. student count
  3. The highest possible value
  4. a variable that is private
  5. find the total

It is important to note that while the C++ standard allows the use of non-ASCII characters as identifiers, it is still recommended to use English characters in actual development to improve code readability and compatibility.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds