C tokens are the basic building blocks in C language that are used to write a C program
Every individual unit in C program is called a token
The following are the 6 types of tokens in C
1) Keywords : The reserved words is C that cannot be used for variable
(eg: auto, double, enum )
2) Identifiers : Names given to constants, variables, structures , functions, array etc
They are used for naming of variables, functions, array etc. These are user-defined names which consist of alphabets, number, underscore ‘_’. Keywords are not used as identifiers.
3) Constants : These are fixed values used in the program and do not change during the program execution
They can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are enumeration constants as well.
Constants are treated just like regular variables except that their values cannot be modified after their definition.
Types of constant
- Integer constants
- Floating point constants
- Character constants
- String constants
- Backslash character constants
There are two simple ways in C to define constants −
- Using #define preprocessor.
- Using const keyword.
4) Strings
A string is an array of characters ended with a null character(\0). This null character indicates that string has ended. Strings are always enclosed with double quotes(“ “).
Let us see how to declare String in C language −
- char string[20] = {‘H’,’e’,’l’,’l’,’o’, ‘\0’};
- char string[20] = “Hello”;
- char string [] = “Hello”;
5) special symbols
eg : (), {}
6) Operators
C operators are symbols that are used to perform mathematical or logical manipulations
- Arithmetic Operators - ( +, /, -, *)
- Relational Operators - ( > , < , != )
- Logical Operators (&&, ||, !)
- Assignment Operators ( -, +=)
- Increment and Decrement Operators ( ++, -- )
- Conditional Operator (?:)
- Bitwise Operators ( <<, >>, &, ^, |)
- Special operator
- & -- address of the memory location
- * pointer to a variable
Example:
int main()
{
int x;
x = 10;
printf ("x = %d \n", total);
}
int - keyword
x - identifier
= - operator
main - identifier
(), {}- special symbols
No comments:
Post a Comment