What is a Variable Name
As we have come to know in a previous post on C++ Variables, that a Variable is a named memory location to store some program data temporarily. "Named Memory Location" tells us that every variable in C++ has a variable name to refer the data stored in it.
Naming Rules To Write C++ variable Names
If we use a variable in a C++ program, we will declare this variable. To declare a C++ variable we will have to use a distinct name for each and every variable. We have to obey the following naming rules to write variable names in C++ programming.- The variable name will start with an alphabet or an Underscore.
- There should be no blank spaces in a variable name.
- Special characters like +, *, &, ^, % cannot be used in variable names.
- Reserved Words or Keywords cannot be used as variable names. Reserved words or keywords are the words used in C++ language for specific purpose. For example, int or for or while are reserved words in C language and C++ programming language, so programmers are not allowed to use these words as variable names in a program.
- Although the maximum length of a variable name is compiler dependent in C++, several C++ compilers allow up to 31 characters long variable names. If anyone uses more than 31 characters for a variable name, extra characters are ignored by the C++ compiler.
- Variable names should be short and precise. Don't use abbreviations that may not self explanatory. Use abbreviations like RollNo in spite of RNo or RN or R or Roll. Abbreviations should be meaningful that may express the purpose of the use of a variable, clearly.
- Use uniform naming conventions in your program. For example: Use of RollNumb as a variable name states that the programmer will use first 4 characters for each word in a variable name. Secondly, each word in a variable name will be capital letter. If you follow uniform naming conventions for variables, writing, changing and maintaining your programs will be much easier. In addition, other programmers will find it easy to understand your programs.
- Variable names must be unique in a program. A variable name can be used only for one data type.
- Use meaningful names that can explain the purpose of using the variable and type of data it can hold.
Start With Alphabets or Underscore
No Blank Space
No Special Characters
No Reserved / Keywords
Up to 31 characters long
Short and Precise
Naming Conventions
Unique Names
Meaningful Names
Variables in C++ | |
1 | Explain Variables in Programming C++ |
2 | Naming Rules For C++ Variables |
0 comments:
Post a Comment
We Love To Hear From You!