Followers

Monday, May 22, 2023

Tokens in C language.

 

Tokens: Tokens are the basic building blocks of a program in C. They are the smallest individual units that make up a C program. In the C programming language, tokens can be classified into several categories. Here's a list of common tokens:

  1. Identifiers:

    • User-defined names used to represent variables, functions, and other entities in a program. Examples: sum, i, calculateArea.
  2. Keywords:

    • Reserved words that have predefined meanings in the C language. Examples: if, while, for, int, return.
  3. Constants:

    • Fixed values that do not change during program execution.
    • Integer constants: Examples: 10, -5, 0xFF.
    • Floating-point constants: Examples: 3.14, -0.5, 1.0e-5.
    • Character constants: Examples: 'A', 'x', '\n'.
    • String constants: Examples: "Hello", "World".
  4. Operators:

    • Symbols that perform specific operations on operands.
    • Arithmetic operators: +, -, *, /, %.
    • Assignment operators: =, +=, -=, *=, /=, %=.
    • Increment/Decrement operators: ++, --.
    • Relational operators: ==, !=, <, >, <=, >=.
    • Logical operators: &&, ||, !.
    • Bitwise operators: &, |, ^, ~, <<, >>.
  5. Delimiters:

    • Symbols used to mark the beginning or end of a statement or block of code.
    • Examples: (, ), {, }, [, ], ,, ;, :.
  6. Separators:

    • Symbols used to separate elements in a list or statement.
    • Example: , (comma).

It's important to note that whitespace (spaces, tabs, newlines) is also considered a token but is generally ignored by the compiler unless it is necessary to separate other tokens.

No comments:

Post a Comment