Tokens in C

C Tokens

Tokens are basic building blocks of a C program. Every single element of a C program has a meaning to the C compiler. And C compiler behaves with those elements in a categorized way. The c program is basically the superset of those elements.

In the C program, there is a total of 6 types of elements can be categorized. The C Tokens are:

  1. Keywords (int, return, if, while, … up to 32 keywords)
  2. Identifiers (Variables, user-defined functions, etc)
  3. Constants
  4. Operators (+, -, ==, etc)
  5. Strings
  6. Special Characters
Keywords & Identifiers

Keywords are predefined words in C compiler that has special meanings and functionality. On the other hand, Identifiers are user-defined data like variables, user-defined functions, etc. In the previous lesson, we learn details about variables. Variables are actually a subset of the Identifiers.

Notes: Identifiers are user-defined data. But any keywords can not be declared as an identifier. We will learn more about keywords and Identifiers in the next lesson.

Constants

The term constant indicates the same meaning of mathematical constant value in the C program. The value of a constant can not be changed. Like value of 5 is always 5, so 5 is a constant.

In the C program, there is a constant data type also. It means defining or declaring a constant. A defined constant value can not be changed throughout the program execution. We will learn more about constant in a later chapter.

Operators

Operators are used for mathematical calculations using operator signs like addition, substruction, multiplication, etc. We will learn everything about operators in a later chapter.

Basically the logical combinations of these six types of programming elements and followed by the basic syntax of C make a complete C program. And using all these emements we can write very basic to very complex source code. We will learn all the elements in the later chapters.

But for now, let’s recall the Hello World program we learned in a previous chapter, then try to identify different kinds of tokens.

Hello World Example:

int main() {
        printf("Hello, World!");
        return: 0;
    }

Where,

  • int – Keyword
  • main – Identifier
  • ( , ;  “”)– Special characters
  • Hello World – String
  • printf – keyword (Library function keyword)
  • return – identifier
  • 0 – constant
  • And all the above are called tokens

Now you should understand the concept of tokens in C. Let’s learn all the tokens respectively.

« Previous Next »