C Tokens and Identifier
C Token
Generally a English Language paragraph consists of words, Numbers and punctuation marks. Similarly a ‘C’ program consists of char, number, string and different types of symbols. These character, Number, String and symbols are called TOKEN in ‘C’ language. The smallest individual unit in a ‘C’ program is called as Token.
C language has six tokens. These are:
1. Keywords
2. Identifier
3. Constants
4. String
5. Operator
6. Symbols
1].Keyword
The predefined words which are provided by the ‘C’ language are called as Keyword. All of the keywords are written in lowercase. All the Keywords are written in lower case.
C language is case-sensitive programming language therefore uppercase and lowercase are different in ‘C’ language. This means that “auto” is a keyword, while “AUTO” is not. We can not use a keyword for any other purpose in a program such as variable or function name.
The C Language provides 32 keywords which are used to create any type of C Language program
int char float double
void signed unsigned short
long ifelse switch case
default for while do
break continue goto return
auto static register extern
struct union enum const
typedef volatile sizeof
2].IDENTFIRE
It refers to the name of variable, constant, array, string, structure and function. They are defined/created by the user. They can contain letter or digit. Both upper case and lower case letters are allowed. We can also use underscore in identifier name.
The following rules are followed when we create an identifier:-
1. Identifier name consist of letter, digit and underscore.
2. The first character must we letter or underscore.
Ex:- int Num1 ; ü
int 1Num ; û
int _Num ; ü
3. Special symbols are not allowed in identifier.
Ex:- int Emp.No; û
Int Roll_No; ü
4. Identifier name should not be keywords.
Ex:- int if; û
int IF; ü
int If; ü
5. Identifire name cannot contains white space.
Ex:- int Roll No; û
int Roll_No; ü
6. Identifire name is case sensitive.The variable ROLLNO is not the same as RollNo.
Ex:- int ROLLNO; int rollno ROLLNO ≠ rollno
int ROLLNO; int RollNo ROLLNO ≠ RollNo
7. There is restriction on the length of identifier but only first 31 characters are significant.
3].CONSTANTS
Constant is like a variable but it is used to store a fixed value. The value of constant does not change during the execution of program. If we try to modify the constant value, the compiler will display an error message.
The constants are used for the following purpose
i).Assign value to variable ii).Compare with variable value iii). In calculation
Types of Constant
We can classify the C language constants into following categories:-
- Numeric constant
- Interger
- Float
- Character Constant
- Character
- String
The const keyword is used to declare constant in c language. When we declare constant we must assign a value to it otherwise compiler display an error message.
1. Integer Constant
2. Float Constant
3. Char Constant
4. String Constant
const DataType ConstName=Value;
const float PI=3.141;
4].STRING
String is a collection of characters, Number and Symbols enclosed within double quotes. It can contain any type of values such as characters, digits, symbols and white space also. String is used to form a word, an identifier or a statement in a program.
Ex: - “Welcome to Spire Academy ”
“123456”
“ENRoll1001”
“Rs 100.65”
5].OPERATOR
Operators are special symbols which are used to perform operation on the given values or variables. The value or variable which are used with operator is called as operand.
Operator
Ex: - 10 + 20
Operand1 Operand2
If operator works on single value then operator is called as unary operator. If operator works on two values then operator is called as binary operator. If operator works on three values it is called as ternary operator.
Ex:- Num++ à Unary Operator
A+B à Binary Operator
10<12 ? “C” : “C++” à Ternary Operator
We can classify the C Language operators into following categories:-
1. Arithmetic Operator
2. Relational Operator
3. Logical Operator
4. Assignment Operator
5. Increment/Decrement Operator
6. Conditional Operator
7. Bitwise Operator
8. Special Operator
6].SYMBOLS
Symbols are important part of C Language program. Without symbols we cannot create any C Programs. Symbols are used to form/create words, number and expressions. Some of the symbols supported by the ‘C’ language are:-
# ; ( ) { } [ ]
? \ _
Comments
Post a Comment