Following are the few basic concept that must be understand before writing a program in C programing language.
The C Character Set:
                                   A character denotes any alphabet, digit or special symbol used to 
represent information.
Variables And Constant:
                a 
variable is an entity that may change, whereas constant is an entity that does not change. In any C program we typically do lots of calculations. The results of these 
calculations are stored in computer’s memory. Like human memory, the 
computer’s memory also consists of millions of cells. The calculated 
values are stored in these memory cells. To make the retrieval and 
usage of these values easy, these memory cells (also called memory 
locations) are given names. Since the value stored in each location may 
change, the names given to these locations are called variable names.
Consider the memory locations shown in Figure 1.3. Here 3 is stored in a 
memory location and a name x is given to it. Then we have assigned a 
new value 5 to the same memory location x. This would overwrite the 
earlier value 3, since a memory location can hold only one value at a 
time.  
Since the location whose name is x can hold different values at different 
times x is known as a variable (or a variable name). As against this, 3 or 5 
do not change, hence are known as constants. 
In programming languages, constants are often called literals, whereas, 
variables are called identifiers. 
Rules for Naming a variable in C:
(a) A variable name is any combination of 1 to 31 alphabets, digits or 
underscores. Some compilers allow variable names whose length 
could be up to 247 characters. Still, it would be safer to stick to the 
rule of 31 characters. Do not create unnecessarily long variable 
names as it adds to your typing effort.
(b) The first character in the variable name must be an alphabet or 
underscore ( _ ).
 (c) No commas or blanks are allowed within a variable name.
 (d) No special symbol other than an underscore (as in gross_sal) can be 
used in a variable name. 
Ex.: 
si_int,  m_hra , pop_e_89 
Since, the maximum allowable length of a variable name is 31 
characters, an enormous number of variable names can be constructed 
using the above-mentioned rules. It is a good practice to exploit this 
abundant choice in naming variables by using meaningful variable 
names. 
Thus, if we want to calculate simple interest, it is always advisable to 
construct meaningful variable names like prin, roi, noy to represent 
Principle, Rate of interest and Number of years rather than using the 
variables a, b, c.
The rules for creating variable names remain same for all the types of 
primary and secondary variables. Naturally, the question follows... how 
is C able to differentiate between these variables? This is a rather simple 
matter. C compiler is able to distinguish between the variable names by 
making it compulsory for you to declare the type of any variable name 
that you wish to use in a program. This type declaration is done at the 
beginning of the program. Examples of type declaration statements are 
given below.
Ex.:
 int si, m_hra ;
 float bassal ;
 char code ;
C Keywords:
Keywords are the words whose meaning has already been explained to 
the C compiler (or in a broad sense to the computer). There are only 32 
keywords available in C. Figure 1.5 gives a list of these keywords for your 
ready reference. A detailed discussion of each of these keywords would 
be taken up in later chapters wherever their use is relevant.
The keywords cannot be used as variable names because if we do so, we
are trying to assign a new meaning to the keyword, which is not 
allowed. Some C compilers allow you to construct variable names that 
exactly resemble the keywords. However, it would be safer not to mix 
up the variable names and the keywords. 
Note that compiler vendors (like Microsoft, Borland, etc.) provide their 
own keywords apart from the ones mentioned in Figure 1.5. These 
include extended keywords like near, far, asm, etc. Though it has been 
suggested by the ANSI committee that every such compiler-specific 
keyword should be preceded by two underscores (as in __asm ), not 
every vendor follows this rule. 
 
 
Comments
Post a Comment