Identifiers, Keywords, and Tokens in C

For Complete YouTube Video: Click Here

In this class, we will try to understand Identifiers, Keywords, and Tokens in C.

Before understanding the concepts of Identifiers, Keywords, and Tokens in C, we will understand the character set.

Character Set of C Programming Language

If we consider any natural language or a programming language, it comprises a set of characters.

For example, if we think of the English language, it contains 26 characters.

Any word or any sentence in English is made up of these 26 characters only.

Similarly, any programming language comprises a set of characters.

The character set in the C Programming language is grouped as shown below.

  1. Alphabets
  2. Digits
  3. Special Characters
  1. Alphabets supported in C are

Uppercase alphabets: 

    A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

Lowercase alphabets: 

    a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z

2. Digits supported are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

3. Special Characters supported are  

~ ` ! @ # $ % ^ & * ( ) _ – + = | \ { } [ ] : ; “ ‘ < > , . ? / 

Any program that you write should be within these character sets.

Identifiers, Keywords and Tokens in C
Character Set of C Programming Language

Identifiers in C

Identifier refers to the name given to entities such as variables, functions, structures, etc.

Rules for naming identifiers:

  1. A valid identifier can have letters (both uppercase and lowercase letters), digits, and underscores.
  2. The first letter of an identifier should be either a letter or an underscore.
  3. You cannot use keywords like int, float, double, etc., as identifiers.

Examples of valid identifiers my_test, _hello_world, abc_123

Examples of invalid identifiers 12_welcome, float

Keywords in C:

The Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax, and they cannot be used as an identifier.

Examples: int, char, for, while, etc.

Tokens in C:

A token is the smallest unit in a ‘C’ program. It is every word and punctuation that you come across in your C program.