Original C dictates that
- The first 31 chars of an internal (i.e. not an external variable) variable name is significant.
- The first 6 characters of an function name or external variable is significant
For C++ (GCC 1024, MS 2048)
another posting says:
- Microsoft C++: 2048 characters
- Intel C++: 2048 characters
- g++: No limit, as answered in this question: is there a length limit on g++ variable names?
another posting says:
Annex B of the C++ Standard says that an implementation should support identifiers at least 1024 characters long, but this is not mandatory.
The C standard, section 220.127.116.11 says:
- 63 significant initial characters in an internal identifier or a macro name (each universal character name or extended source character is considered a single character)
- 31 significant initial characters in an external identifier (each universal character name specifying a short identifier of 0000FFFF or less is considered 6 characters, each universal character name specifying a short identifier of 00010000 or more is considered 10 characters, and each extended source character is considered the same number of characters as the corresponding universal character name, if any)
Implementations should avoid imposing fixed translation limits whenever possible. So you should check your documentation to see if your compiler supports a greater number of significant characters in identifiers.
Rules For Constructing Variable Name
Characters Allowed :
- Capital Letters ( A – Z )
- Small Letters ( a – z )
- Digits ( 0 – 9 )
- Blanks & Commas are not allowed
- No Special Symbols other than underscore(_) are allowed
- First Character should be alphabet or Underscore
- Variable name Should not be Reserved Word
Naming Rules for Variables
- Variable names in Visual C++ can range from 1 to 255 characters. To make variable names portable to other environments stay within a 1 to 31 character range.
- All variable names must begin with a letter of the alphabet or an underscore( _ ). For beginning programmers, it may be easier to begin all variable names with a letter of the alphabet.
- After the first initial letter, variable names can also contain letters and numbers. No spaces or special characters, however, are allowed.
- Uppercase characters are distinct from lowercase characters. Using all uppercase letters is used primarily to identify constant variables.
- You cannot use a C++ keyword (reserved word) as a variable name.
- C/C++ – Variable and method name length limit
- What is max length for an C/C++ identifier on common (build) systems?
- Identifiers (C++)
- Max identifier length
In C the length of a variable name is unlimited (although the first 31 characters must be unique). So variable names like these:
disk_name total_count last_entry
- File Basics, Comments, and Program Headings
- Style and Program Organization
- Statement Formatting
- Statement Details
- Directory Organization and Makefile Style