We should have the basic knowledge to learn any programming language. Only then can you understand a language well and can also write it. If you do not learn basic then it becomes very difficult for you to understand any programming language.
In this tutorial, we'll explain C language tokens in detail.
Tokens in C programming language
While a program in C language, we use many words which we need to make a program because many words are used to complete a statement, which have their own different characteristics. if we understand the C program in simple words, the program is divided into small units, and the smallest unit among them is called the token. All tokens play a very important role while writing programs in C language.
Example of tokens in C
If we understand from a simple example, we use many words to write any line, now those words also have different meanings which form a complete sentence. Now if you do not know about those words then it becomes difficult to write and understand a sentence.
Similarly, to write programs in C language, we use very small units to write a program, which we call tokens.
Now you must have understood how important a role tokens play in the C programming language.
Types of tokens in C
There are 6 types of tokens in C language which have their different characteristics.
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operators
Now, let's understand each type of C token in detail.
Keywords in C:-
It's clear from the name of the Keyword that some words that have already been defined in C programming language are used based on their characteristics.
Keywords are predefined or reserved words that cannot be used as variables because each keyword has a different function. So while writing a C program, you need to know about all the keywords so that you do not use any keyword with a variable because at that time its meaning becomes different.
Keywords are reserved words that should be used only in the right place. These keywords are very necessary while making C programs. Not only in C programming but in other programming languages also keywords are used at the right places which fulfill the minor shortcomings of the program. As mentioned above, these words are pre-defined. Pre-defined here means the words which have already been fixed and whose meaning cannot be changed. While running the program, first the C program is compiled and then the output is shown, then there the compiler already knows what the meaning of which keyword is and for what it is being used. The meaning of the keyword cannot be changed.
There are 32 keywords in the C language. All these keywords are written in lowercase (small letters) only. If these are not written correctly then the errors are seen in the C program.
Auto
|
double
|
int
|
Struct
|
Break
|
else
|
long
|
Switch
|
Case
|
enum
|
register
|
Typedef
|
Char
|
extern
|
return
|
Union
|
Const
|
short
|
float
|
Unsigned
|
Continue
|
for
|
signed
|
Void
|
Default
|
goto
|
sizeof
|
Volatile
|
Do
|
if
|
static
|
While
|
All the keywords are given above which are used to complete code lines.
2. Identifiers in C –
C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier begins with the letters A to Z, a to z, or the underscore '_'
Just like people are identified by their names like Jack, John, and various types of items like Mobiles, Laptops, and cars have different names that identify them. So, every item has its name, called an identifier which has different names that tell its identity.
Identifiers are user-defined, and set by the programmer, such as variable names, function names, or array names. All identifiers have different names; no identifier name can be the same. If you want to use keywords for identifier names, you can't because keywords are reserved words that cannot be changed.
Special symbols like @, $, and % are not allowed in the names of C identifiers.
C is a case-sensitive programming language. Hence, 'Route' and 'route' are different identifiers in C.
There should not be white space in the name of identifiers.
The length of Identifiers does not exceed 31 characters.
Identifiers' names never start with a number.
Example of identifiers in C language
mohan_kumar |
abc |
movie_name |
a_123 |
myname123 |
_hello |
b33a2 |
newPost |
a898_va |
Constants in C programming | C Literals:-
Constants are those whose value cannot be changed. Once the constant value is declared, that constant value becomes fixed in which no change can be made at run time. In simple language, a Constant is the opposite of a variable because the value of a variable can be changed at run time but once the value of the constant is declared, that value cannot be changed at run time. The behavior of a constant is static, which means that the value of a constant cannot be changed at run time. The values of constants are fixed due to which we also call constants as literals.
In C Programming, constant can be declared in two ways.
Using #define pre-processor
Using const keyword
String in C –
The string is a sequence of characters like “Hello World”. The string can be terminated by null. The string is a simple array whose data type is char.
How to declare string in the C programming Language
As you know a string is a simple array, to declare the string it is very important to understand its syntax.
Syntax of string in C
Char str_name[size];
In the string syntax given above, str_name is a name given to the string variable to which anything can be given. Along with this, the size also has to be defined as to what length the characters have to be stored.
In what ways can String be defined?
There are many ways to define a string which are given below.
char str [] = "TECHNO";
char str [45] = "TECHNO";
char str [] = {'T','E','C','H','N',’O’,' 0'};
char str [45] = {'T','E','C','H','N',’O’,' 0'};
Operators in C Programming Langauge –
We start using operators from small school classes. In simple language, when we do addition, subtraction, multiplication, or division, then we use signs like +, and -, We used to call them signs but in C or other programming languages, we call them operators. Operators are used for special operations. As -
a-b
In the example given above – the sign is operator and a and b are operands. Operators are used for some specific mathematical logic and are also used in creating the logic of the function.
Types of Operators in C programming language-
Unary operators in C -
Such operators that require only one operand to operate are called Unary Operators. For example, increment and decrement operators require only one operand to operate. increment operator (++), decrement operator (--), and sizeof, (type)*, etc. are Unary Operators.
Binary Operators in C programming
In unary operators, you saw that we were creating logic with a single operand but in binary operators, we need more than one operand. We call them binary operators.
Binary operators are of the following types.
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Misc Operators
Special Symbols in C Programming
Special symbols or characters are used for specific purposes in the C programming language.
Let's understand the commonly used symbols in C:
- Parentheses (): Used to create functions or call functions and to create logical blocks.
- Brackets []: Used to create arrays.
- Curly Braces {}: Used to create blocks of code.
- Comma (,): Used to separate elements in arrays or statements.
- Semicolon (;): Terminates a statement, indicating its end.
In this way, tokens are used to create C programs. Token is the smallest unit of program which together forms a C program.