Tokens in C is the most important element to be used in creating a program in C. We can define the token as the smallest individual element in C. For `example, we cannot create a sentence without using words; similarly, we cannot create a program in C without using tokens in C. Therefore, we can say that tokens in C is the building block or the basic component for creating a program in C language.

Classification of tokens in C


C Supports 6 Types of Tokens

  1. Keywords
  2. Identifiers
  3. Strings
  4. Operators
  5. Constants
  6. Special Characters

1. Keywords

Keywords in C language are predefined or reserved keywords used to expose the behavior of the data. There are 32 keywords in C. Each keyword has its functionality to do.

Syntax:

2. Identifier

Identifier in C language is used for naming functions, variables, structures, unions, arrays, etc. The identifier is user-defined words. These identifiers can be composed of uppercase, lowercase letters, digits, underscore. Identifiers never used for keywords. Rules to construct identifiers is below

  • The first character should be either alphabet or underscore and then followed by any character, digit.
  • Identifiers are case sensitive as there is Aand a treated as different.
  • Commas and blank space are not allowed
  • Keywords can’t be used for identifiers.
  • The length of the identifiers should not be more than 31 characters.
  • Naming convention should understandable to the user.

3. Strings

Strings in C is an array of characters having null character ‘\0’ at the end of the string. Strings in C are enclosed in double-quotes(“”) and Characters are enclosed in single quotes(”).

Syntax:

char a[10]={'1','2','3'};
char a[]="Amardeep";
char a[10]="Paramesh";

4. Operators

This is used to perform special operations on data.

Unary Operator: A unary operator is an operator applied to the single operand. For example: increment operator (++), decrement operator (--), sizeof, (type)*.

Binary Operator: The binary operator is an operator applied between two operands. The following is the list of the binary operators:

  • Arithmetic Operators
  • Relational Operators
  • Shift Operators
  • Logical Operators
  • Bitwise Operators
  • Conditional Operators
  • Assignment Operator
  • Misc Operator

5. Constants in C

A constant is a value assigned to the variable which will remain the same throughout the program, i.e., the constant value cannot be changed.

There are two ways of declaring constant:

  • Using const keyword
  • Using #define pre-processor

Types of constants in C

6. Special Characters in C

Some special characters are used in C, and they have a special meaning which cannot be used for another purpose.

  • Square brackets [ ]: The opening and closing brackets represent the single and multidimensional subscripts.
  • Simple brackets ( ): It is used in function declaration and function calling. For example, printf() is a pre-defined function.
  • Curly braces { }: It is used in the opening and closing of the code. It is used in the opening and closing of the loops.
  • Comma (,): It is used for separating for more than one statement and for example, separating function parameters in a function call, separating the variable when printing the value of more than one variable using a single printf statement.
  • Hash/pre-processor (#): It is used for pre-processor directive. It basically denotes that we are using the header file.
  • Asterisk (*): This symbol is used to represent pointers and also used as an operator for multiplication.
  • Tilde (~): It is used as a destructor to free memory.
  • Period (.): It is used to access a member of a structure or a union.