World's most popular travel blog for travel bloggers.

Variables Naming Rules

, , No Comments
Naming Rules for Variables
The names of variables in the C++ language are referred to as identifiers.   The best naming convention is to choose a variable name that will tell the reader of the program what the variable represents. Variables that describe the data stored at that particular memory location are called mnemonic variables.
Rules for naming 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.



Tip:  Some programmers use an underscore in variable names to separate parts of the name, such as shipping_weight. Others prefer a "capital style" notation, such asshippingWeight to separate parts of the name. 

NEVER use uppercase for every letter in a variable name, because uppercase names are reserved for constant variables.

Samples of acceptable variable names: Samples of unacceptable variable names:
Grade Grade(Test)
GradeOnTestGradeTest#1
Grade_On_Test3rd_Test_Grade

0 comments:

Post a Comment

Let us know your responses and feedback