Presentation Transcript
Slide 1:C – Token:
Individual words and punctuation words are called Tokens
Keywords
Identifiers
Constants
Strings
Operators
Special symbols
Slide 2:Keyword:
C word is classified as either a key word or identifier
All keywords have fixed meaning and meaning cannot be changed
It serves as a basic building blocks of program statement
All keywords must be written in lower case
Slide 3:Identifiers:
It refers to the names of variables, functions and arrays
These are user defined name and consist of sequence of letters and digits as first characters
Both upper and lower cases are permitted
Underscore (-) character is allowed in identifier. It is usually used as a link between two words in long identifier
Constants:
The value of the constants do not change during the execution of the program.
Slide 4:Constants
Numeric constants Character constants
Integer Real Single String
Constant Constant character constant
constant
Slide 5:Back slash character constant
#include
main()
{
printf(“Hello \n world”);
}
C supports some special back space character that are used in output function.
Integer Constant:
An integer constant refers to a sequence of digits. There are three types.
Slide 6:Decimal:
It consist a set of digits 0 – 9
It is proceeded by an optional + (or) – sign
Valid Eg:
+823; -726; 0
Invalid Eg:
#750;20,750;44 440
Slide 7:Octal:
It consist of any combination of digits from the set 0 to 7 with a leading 0
Valid Eg:
037
0
0752
Slide 8:Hexa decimal:
Sequence of digits proceeded by ox (or) OX is considered as hexa decimal integer. It includes alphabets A to F, to represent numbers 10-15
Valid Eg:
OX2 ; OX9F
Slide 9:Real constants:
Integer numbers are inadequate to represents quantities that vary continously such as distance, height, temperature, prices & soon.
These quantities are represented by numbers containing fractional part. Such numbers are called real constants
Eg:
0.004; -83 ------- Invalid
-0.43; 254.0 ------ Invalid
In above deciaml notation having a whole number followed by fractional part. It is possible to omit digits before and after the decimal points.
Eg: 254, .04, +.21, -.54
Slide 10:Mantissa e exponent:
Number in mantissa is either a floating point or integer.
Exponent must be an integer number with the optional + or – sign.
The letter e separating a mantissa and exponent can be written in lower or upper case.
Examples:
2.75 e 4 - valid
12 e -2 - valid
1.5 e +5 - valid
-1.2 e -1 - valid
-52 e 62.5 - Invalid
Slide 11:Single character constant:
A single character constant contains a single character enclosed within a pair of single quotes
Example:
‘5’ , ‘1’ , ‘ ‘
Character constants have integer value known as ASCII value
printf(“%d”, ‘a’);
printf(“%c”,’97’);
Slide 12:String constant:
A string constant is a sequence of character enclosed in double quotes
Example:
“welcome”
“1884”
“* - *”
“5+3”
Slide 13:Sample program:
(1) #include
main()
{
printf(“%d”, size of (char));
printf(“%d”, size of (int));
printf(“%d”, size of (float));
}
Output:
1
2
4
Slide 14:(2) #include
main()
{
int i;
int f;
int c;
printf(“%d”,size of (i));
printf(“%f “,size of (f));
printf(“%c”,size of (c));
}
Slide 15:(3) #include
main()
{
char ch=291;
printf(“%c”,ch);
}
Output:
291
The range of the character must be within the range of
[ -128 to +127 ]
So it is error