Skip to main content

Posts

Showing posts with the label Tokens in C

Tokens in C with example

 In C programming, a token is the smallest individual unit in the source code that the compiler can understand. Tokens are building blocks of C programs and are used to form expressions, statements, and other elements in the code. C tokens are of various types, such as keywords, identifiers, constants, strings, operators, and punctuators. Let's explore each type of token with examples: 1. Keywords: Keywords are reserved words in the C language that have a specific meaning and cannot be used as variable names. Examples of C keywords include `int`, `float`, `if`, `else`, `for`, `while`, etc. ```c #include <stdio.h> int main() {     int num = 10;  // 'int', 'main', 'return' are keywords     if (num > 0) {         printf("Positive number\n");  // 'if', 'printf' are keywords     }     return 0;  // 'return' is a keyword } ``` 2. Identifiers: Identifiers are names used t...