Variable Names and keywords in C Language

Keywords in C 

Each of the types shown in Table 3-1 (i.e., boolean, char, int, etc.) are keywords in C. A keyword is any word that has special meaning to the C compiler. Because keywords are reserved for the compiler’s use, you cannot use them for your own variable or function names. If you do, the compiler will flag it as an error. If the compiler didn’t flag such errors, then the compiler would be confused as to which use of the keywords to use in any given situatin.



                                                               Table 3-1. C Value Data Types
Variable Names in C
If you can’t use keywords for variable or function names, then what can you use? There are three general rules for naming variables or functions in C: Valid variable names may contain:
  1. Characters a through z and A through Z
  2. The underscore character (_)
  3. Digit characters 0 through 9, provided they are not used as the first character in the name.
Just about everything else is not acceptable, including C keywords. That also means that punctuation, and other special non-printing characters are not allowed either. Valid variable names might include:
jane          Jane      ohm             ampere  volt
money     day1      Week50    _system XfXf
Using the same rules, the following would not be valid names:
^carat                      4July                      -negative               @URL
%percent                not-Good                This&That             what?
Given these limits, how does one create a “good” variable name? As a general rule, variable names that are long enough to give me a clue as to what they do in a program but short enough that don’t get tired of typing their name. Another convention a lot of programmers used is a variant of what’s called camel notation. Using this notation, variable names begin with a lowercase letter with each subword capitalized. Examples using this style might be:
myFriend        togglePrinter   reloadEmptyPaperTray    closeDriveDoor
 you will write perfect (error-free) code every time you write a program. Using variable names that make sense and are easy to read makes debugging just that much easier. ( C is case sensitive, which means that myData and MyData are two different variables).
www.cinterviews.com appreciates your contribution please mail us the questions you have to cinterviews.blogspot.com@gmail.com so that it will be useful to our job search community

No comments: