This article provides a comprehensive overview of C tokens. We will learn what is a token and what are the different tokens in C programming language.
Introduction
A programming language is designed to help process certain kinds of data consisting of numbers, characters and strings and to provide useful output known as information.
The task of processing data is achieved by writing instructions. These set of instructions is known as a program. Programs are written using words and symbols according to the rigid rules of the programming language known as syntax.
Watch this video to learn about C tokens:
Character Set
The characters that can be used to form words, numbers and expressions depend upon the computer on which the program is run. The characters in C, are grouped into the following four categories:
1) Letters
2) Digits
3) Special Characters
4) Whitespaces
The compiler ignores the white spaces unless they are part of the string constants. White spaces are used to separate words from each other, but they cannot be used in between the characters of keywords and identifiers.
Tokens in C
In a paragraph of text, individual words and punctuation marks are considered as tokens. Likewise in a C program, the smallest individual units are known as C tokens. C has six types of tokens as shown below. C programs are written using these tokens and the syntax of the language.
Keywords
Every word used in a C program is classified as either a keyword or as an identifier. A keyword in C is a reserved word which has a specific meaning. Keywords in C cannot be used as identifiers. Keywords serve as the basic building blocks for program statements.
Keywords in C are always in lowercase. ANSI C supports 32 keywords which are listed below:
Identifiers
Identifiers refer to the names of variables, functions and arrays. These are user-defined names and consist of sequence of letters and digits, with a letter as a first character. Both uppercase and lowercase letters can be used, although lowercase letters are generally used. The underscore character is also permitted in identifiers.
There certain rules while writing identifiers. They are as follows:
1) First character must be an alphabet or underscore.
2) Must consist of only letters, digits or underscore.
3) Only first 31 characters are significant.
4) Cannot use a keyword.
5) Must not contain white space.
Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.
He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.
He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.
Leave a Reply