C Tokens - Definition, Diagram, and its Types

In this tutorial, we will learn about C tokens and types of tokens in C. Tokens are the smallest individual unit or building block of a program that conveys special meaning to the language compiler. C Token is also known as Lexical Units. 

C Token Diagram


C Tokens
C Token Diagram

Types of C Token are

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

Keywords in C

Keywords are reserved words having a special meaning in the programming language. These Keywords in c are pre-defined words in a programming language that convey a special meaning to the compiler. 

C language supports 32 keywords. C keywords classification which is given below



auto
double
int
struct
break
else
long
switch
case
enum
register
typedef
char
extern
return
union
const
float
short
unsigned
continue
for
signed
void
default
goto
sizeof
volatile
do
if
static
while

Identifiers in C

The identifier is a fundamental building block and is used as the general terminology for names given to different parts of programs are variables, arrays, and functions. 

Rules for naming identifiers

  • The first character must be Letter(A-Z or a-z) or Underscore(_).
  • You can not use any special symbol in identifier i.e. @,+,-,., etc.
  • You can not use keywords as identifiers.
  • It should not contain any space between them.
  • In the same program, two or more same identifiers are not possible.

Some examples of identifiers in c are


_file            Valid
MY.DOB     invalid because it contains a special symbol dot(.)


Constants in C

Constants refer to fixed values. Constants in c like any other normal variables of the program but the only difference is once you defined than their data items( values ) that never change or modify their value during execution of a program. These are also known as Literals.

Following are the various types of constants c token

  1. Integer Constants
  2. Character Constants
  3. Floating Constants
  4. String constants

Operators in C token

Operators are that are trigger some calculus when applied to variables in an expression. Operators are acts on operands (Operands are data items on which operators act.)

C token Operators are classified on the basis of the number of operands are

  • Unary Operators: These are operators those required one operand to operates. 
   Some unary operators are followed:
       ++ increment 
       -- decrement, etc.

  • Binary Operators: These are operators that required two operands to operates on it.
 Some Binary Operators are followed:

  1. Arithmetic operators
  2. Assignment Operators
  3. Bitwise Operators
  4. Conditional Operators
  5. Logical Operators
  6. Relational Operator

Strings in C token

A string in c token is a character array that ended with a null character (‘\0’). Null character shows the end of the character array. Strings are always enclosed in double quotes(“”) and character is enclosed by single quotes(‘’).

Examples
char string[20] = “codeamy”; \\ In this 20 bytes of memory space is allocated by programmers to holding the string.
(or)
char string [] = “codeamy”; \\ In this memory space is allocated by the compiler at the time of execution.
(or)
char string[20] = {‘c’, ’o’, ‘d’, ‘e’, ‘a’, ‘m’, ‘y’, ‘\0’};

Special Symbols in C Token

C token has special symbols used that have special meanings that cannot be used for another purpose. 
  1. Asterisk (*)
  2. Assignment operator
  3. Curly Braces { }
  4. Comma (,)
  5. Parentheses ( )
  6. Preprocessor (#)
  7. Square Brackets [ ]
  8. Semicolon (;)
In the above article on C tokens and types of token in C, If you have any doubt and also share your experience in the comment box below. 

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form