Author Topic: Identifiers in C++ (Some rules and Tips)  (Read 166 times)

Offline mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 2594
    • View Profile
    • Engineering Forum
on: September 27, 2018, 12:15:23 PM
C++ Identifiers

Just as every entity in the real world has a name, so you need to choose names for the things you will refer to in your programs. Programming languages use special symbols called identifiers to name such programming entities as variables, constants, and functions. Here are the rules for naming identifiers:

1. An identifier is a sequence of characters that consists of letters, digits, and under score (_).
2. An identifier must start with a letter or an underscore. It cannot start with a digit.
3. An identifier can not be a reversed word.
4. An identifier can be of any length, but your C++ compiler may impose some restriction. Use identifiers of 31 characters or fewer to ensure portability.

For Example: area and radius are legal identifiers, whereas 2A and d+4 are illegal identifiers because they do not follow the rules. The compiler detects illegal identifiers and reports syntax errors.

Note: Since C++ is case sensitive, X and x are different identifiers.