In C programming, tokens are the smallest units of a program that are meaningful to the compiler. They are building blocks for writing code and include keywords, identifiers, constants, strings, operators, and special symbols.
int
, return
, if
, etc.+
, -
, and *
.()
, {}
, []
, and ;
that have special syntactical roles.The keywords are pre-defined or reserved words in a programming language. Each keyword is meant to perform a specific function in a program.
int main() {
return 0;
}
Identifiers are names given to various program elements like variables and functions by the programmer. They must begin with a letter or underscore, followed by letters, digits, or underscores.
int result;
float totalSum;
Constants are values that remain fixed throughout the program. They can be of various types, such as integer, floating-point, and character constants.
const int MAX_LIMIT = 100;
char ch = 'A';
MAX_LIMIT
is a constant and cannot be modified after initialization.ch
is assigned the character 'A'.Strings are sequences of characters enclosed in double quotes, used to represent text.
char greeting[] = "Hello, World!";
Operators are symbols that tell the compiler to perform specific mathematical, relational, or logical operations on variables and constants.
int sum = 5 + 3;
int product = 5 * 10;
Symbols that have special meanings and are used in various contexts within the program.
Apart from the symbols defined as operators, the other symbols include punctuation symbols like commas, semicolons, and colons. In C, you find them used differently in different contexts.
Understanding tokens is essential for learning C programming. Each type of token has a unique role in structuring and defining the functionality of your code, making your programs both readable and efficient.