What is Tokens in C?
In C programming language, a token is the smallest unit of a program that is meaningful to the compiler. Tokens are the basic building blocks of a C program and they are used to create the syntax and structure of the language.
Types of Tokens in C:
There are six types of tokens in C programming language:
- Keywords: Keywords are reserved words that have a specific meaning in the C language. They cannot be used as variable names or other identifiers. Examples of C keywords include
int
,float
,if
,while
, andreturn
. - Identifiers: Identifiers are user-defined names that are used to represent variables, functions, arrays, and other user-defined entities in a C program. Identifiers must begin with a letter or underscore and can consist of letters, digits, and underscores.
- Constants: Constants are fixed values that cannot be modified during program execution. There are two types of constants in C: numeric and character constants. Numeric constants can be represented in decimal, octal, or hexadecimal format. Character constants are enclosed in single quotes and represent a single character.
- Strings: Strings are sequences of characters enclosed in double quotes. They are used to represent text data in a C program.
- Operators: Operators are symbols that are used to perform operations on variables and constants. Examples of C operators include arithmetic operators (+, -, *, /), relational operators (>, <, ==), and logical operators (&&, ||).
- Special Symbols: Special symbols are used to separate or group different elements of a C program. Examples of special symbols include commas, semicolons, parentheses, and braces.
Each token in C has a specific purpose and meaning, and they are used to build the syntax and structure of the language. For example, keywords are used to specify the data type of a variable or to control the flow of a program, while operators are used to perform mathematical or logical operations on variables and constants.
One important thing to note is that white spaces like blank spaces, tabs, and newline characters are not considered as tokens in C. These are simply used to separate tokens and make the code more readable.