Storing Information with Variables
A Variable IS A Named Data Storage Location In Your Computer's Memory. By use a variable's name in your program, you are, in effect, referring to the data stored there.
Variable names
To Use Variables in your C Programs, You Must Know How To Create Variable Names. In C, Variable Names Must Adhere To The Following Rules:
THE NAME CAN Contain Letters (A to Z and A TO Z), DIGITS (0 to 9), and the understand character character (_). The first character of the name must be a letter. The underst character is Also A Legal First Character, But ITS USE IS NOT Recommended At The Beginning of A Name. A Digit (0 to 9) Cannot Be Used As The First Character. Case Matters (That IS, Upper- and LowerCase Letters). C Is Case-Sensitive, Thus, The Names Count And Count Refer to Two Different Variables. C Keywords CAN't Be Used As Variable Names. A Keyword Is A Word That Is Part of The C Language. (a COMPLETE LIST OF THE C Keywords Can Be Found in appendix b, " Reserved Words. ")
The Following List Contains Some Examples of Legal and ILLEGAL C Variable Names:
Variable Name LegalityPercent Legal y2x5__fg7h Legal annual_profit Legal _1990_tax Legal but not advised savings # account Illegal: Contains the illegal character # double Illegal: Is a C keyword 4sale Illegal: First character is a digit
Because C is case-sensitive, the names percent, PERCENT, and Percent would be considered three different variables. C programmers commonly use only lowercase letters in variable names, although this is not required. Using all-uppercase letters is usually reserved for the Names of Constants (Which Are Covered Later Today).
For many compilers, a C variable name can be up to 31 characters long. (It can actually be longer than that, but the compiler looks at only the first 31 characters of the name.) With this flexibility, you can create variable names that reflect the data being stored. For example, a program that calculates loan payments could store the value of the prime interest rate in a variable named interest_rate. The variable name helps make its usage clear. You could also have created a variable named x or even ozzy_osborne; it does not matter to the C compiler The use of the variable, however, would not be nearly as clear to someone else looking at the source code Although it might take a little more time to type descriptive variable names,.. the improvements in program clarity make it worthwhile.Many naming conventions are used for variable names created from multiple words You've seen one style:... interest_rate Using an underscore to separate words in a variable name makes it easy to interpret T he second style is called camel notation. Instead of using spaces, the first letter of each word is capitalized. Instead of interest_rate, the variable would be named InterestRate. Camel notation is gaining popularity, because it's easier to type a capital letter than an underscore .........................
Do Use Variable Names That Are Descriptive.
Do Adopt and Stick with a style for naming your variables.
Don't Start Your Variable Names with an underscore Unnecessarily.
Don't name your Variables with all capital letters unnecessarily.