Tokens in C Programming language
Tokens in C programming Language :
- C Tokens are smallest Individual unit of a c program or Base Unit of C language. Tokens are Building blocks of C program.
- A C program is Collection of C Tokens.
- Few examples of tokens are keywords, operators, separators, constants, Identifiers, etc.
- We can’t split the Token because token is smallest block of C program.
Let’s look at a example program to understand the C Tokens.
Example program to understand the Tokens in C Language :
1 2 3 4 5 6 |
#include<stdio.h> void main() { printf("Welcome to Sillycodes \n"); return; } |
Output :
1 |
Welcome to Sillycodes. |
Above program is basic Hello world program and It is executed without any errors and we got the result.
If we notice, There are lot of tokens invloved in the above program, Those tokens are
- void keyword and one token.
- The main function is an Keyword/Identifier and it also one token.
- printf also a function, And it is also one token.
- And Finally the return and {..} all are tokens.
Note : We can’t split Tokens.
Example 2 : Spliting the Tokens :
1 2 3 4 5 |
vo id ma in () { pri ntf("Welcome to Sillycodes n"); ret urn; } |
Output :
1 |
Error. |
If you see above program, I try to divide the token. but i got compilation errors.. Because Token is the smallest Individual element in C program. we can’t divide it.
Note : We can’t split C tokens but we can have any number of spaces and tabs and newlines between two tokens.
Example 3 : Spaces between the Tokens :
1 2 3 4 5 6 7 8 |
void main () { printf ("Welcome to Sillycodes "); } |
Output :
1 |
Welcome to Sillycodes |
From above program it is clear we can have any number of spaces, tabs, etc. between two tokens. But we can not split a C token. because Token is the Smallest individual Element in C program.
You Might also like :
- Compilation Phases of C program.
- Structure of C program Explained in Detail.
- Arithmetic Operators with Examples.
- Arithmetic operators priority and it’s Associativity.
- Modulus Operator and Hidden Concepts of Modulus Operator.
- Precedence Table or Operators Priority Table.
- Assignment Operator, Usage, Examples
- Increment Operator and Different types of Increment operators Usage with Examples.
- Decrement Operator and Different types of Decrement operators with Examples.
- Logical Operators tutorial with Examples.
- Relational Operators Tutorial with Examples.
- Conditional Operator tutorial and In depth analysis.
- Comma Operator Tutorial.