C TOKENS:
The Smallest individual units are known as ‘C’ Tokens.‘C’ as six types of tokens:
1. KEY WORDS
2. IDENTIFIERS
3. CONSTANTS
4.VARIABLES
5.READING VARIABLES or INPUT VARIABLE
6.PRINTING VARIABLE or WRITING VARIABLES or OUTPUT VARIABLE
1. KEY WORDS:
Key words are the pre-defined names and the main meaning of keywords can’t be changed during the execution of programs and all the keywords must be written in Lower Case.
The following list shows the reserved words in ‘C’. These reserved words may not be used as constant value or as other identifier.
auto
|
double
|
int
|
struct
|
break
|
else
|
long
|
switch
|
case
|
enum
|
register
|
type def
|
char
|
extern
|
return
|
union
|
const
|
float
|
short
|
unsigned
|
continue
|
for
|
signed
|
void
|
default
|
goto
|
size of
|
volatile
|
do
|
if
|
static
|
while
|
2. IDENTIFIERS:
Identifiers refers to the names of the variables ,functions, arrays. These are user defined names and consists of a sequence letters and digits. Both upper and lower case letters are permitted.
NOTE: The Underscore(_) characters are also permitted in identifiers.
Example: Ram_charan123, Ram_123
3. CONSTANTS:
The term constant means that it does not change during execution of a program.
I)NUMERICAL CONSTANTS: They are of two types,
1 Integer constants
2.Floating point constants
1.INTEGER CONSTANTS:
These are three types of constants. Integer constants are allowed in ‘C’. They are
1.Decimalconstants
2.Octalconstants
3.HexaDecimalconstants
DECIMAL CONSTANTS:
The allowed digits in decimal constants are 0,1,2,3,4,5,6,7,8,9.
Example:(1459)10 whose base or radix is 10
OCTAL CONSTANTS:
The allowed digits in octal constants are 0,1,2,3,4,5,6,7. The octal constants are preceded by‘0’
Example: (147)8 whose base or radix is 8
HEXA DECIMAL CONSTANTS:
It is a sequence of digits from 0-9,10,11,12,13,14,15
A , B, C, D, E, F
Example: (9A4F)16 =(0x9A4F)16 whose base or radix is 16
(14AF)16=(0x14AF)16
2.FLOATING POINT CONSTANTS:
These are represented in two ways. They are
1.Fractional Form
2.Exponential Form
FRACTIONAL FORM:
This must have atleast one decimal point to the right of decimal point.
Example:145.7,7.54
EXPONENTIAL FORM:
It consists of a Mantissa and an exponent. The Mantissa must have atleast one digit after the decimal .The Mantissa is followed by a letter ‘e’or‘E’ and the exponent. The exponent must be an integer with out a decimal point and must have atleast one digit.
Example:
1.4e3=(14/10)* 103=(14/10)*1000=1400.000000
15.67e4=(1567/10)*104=(1567/100)*10000=15670.000000
147.5e5=(1475/10)*105=(1475/10)*100000=14750000.000000
197.65e7=(19765/100)*107=19765*105=1976500000.000000
II) CHARACTER CONSTANTS: They are of 3 types. They are:
1.Single character constant
2.String constant
3. Back slash constant
1.SINGLE CHARACTER CONSTANT:
It contains a single character enclosed with in a pair of single quote marks.
Example:‘A’,’5’,‘H’
2.STRING CONSTANTS:
It is a sequence of characters enclosed in double quotes. The character may be a number (or) a letter (or) a special character (or) blankspace.
Example: “A”, “Well Done”, “1943 Love Story”
3.BACK SLASH CHARACTER CONSTANTS :
'C' supports some special Back Slash Character Constants that are used in output functions. This character constants are known as ‘Escaped Sequences’.
Example:
\n–New line
\b–Back Space
\a–Bell Sound
\t–Tab
4.VARIABLES :
A variable is a data name that may be used to store a data value,unlike constants they do not remain unchanged during the execution of program.A variable may take different values at different times during execution
Example: sum,total etc
RULES FOR VARIABLES :
They must begin with a letter
ANSI standards recognizes a length of 31 characters However length should not be normally more then 8 characters since only the first 8 characters treated significant by many compilers
Upper case and lower case are significant
Example: TOTAL & total are different
It should not be a keyword
5.READING VARIABLES or INPUT VARIABLE :
A variable which reads the value from the keyboard with the function scanner is
scanf("control string" ,argument list);
The control string parameter tells how many values and what type of values reading from the keyboard
The argument list parameter tells where to store the values of these variables ,here the address can be obtained by placing an am-percent symbol (&) before the variable name
6.PRINTING VARIABLE or WRITING VARIABLES or OUTPUT VARIABLE :
A variable which prints the values of the variables by using a function printf is
printf("control string" ,argument list);
The control string parameter may include either of string of characters or format specifiers or both which tells the type of values to be printed
The argument list parameter tells which variable to be printed
Example: printf("The answer to the above is %d",n);