Загрузка...

Tokens in C Programming

In C programming, a token is the smallest individual unit of a program that is recognized by the compiler. During compilation, the source code is first broken down into these meaningful units called tokens in a process known as lexical analysis. Tokens help the compiler understand the structure and syntax of the program. In general, C tokens are classified into five main categories: keywords, identifiers, constants (literals), operators, and punctuators (special symbols).

1. Keywords

Keywords are reserved words in C that have predefined meanings and functions. They form the basic building blocks of the language syntax and cannot be used as names for variables or functions. Examples of keywords include int, float, char, if, else, for, while, return, break, and continue. For instance, in the statement int a = 10;, the word int is a keyword that specifies the data type of the variable.

2. Identifiers

Identifiers are names given to program elements such as variables, functions, and arrays. They are used to identify these elements in a program. An identifier must begin with a letter (a–z or A–Z) or an underscore _, followed by letters, digits, or underscores. Identifiers must not be keywords and cannot contain special characters or spaces. Examples of valid identifiers are sum, total_marks, and _count, whereas 2num and float are invalid identifiers. In the statement float area;, area is an identifier representing a variable name.

3. Constants (Literals)

Constants are fixed values that do not change during the execution of a program. They are also called literals. C supports several types of constants such as integer constants (10, -25), floating-point constants (3.14, 2.5e3), character constants ('A', '\n'), and string constants ("Hello"). In addition, symbolic constants can be defined using the #define directive, for example #define PI 3.14. In the statement int x = 10;, the value 10 is a constant.

4. Operators

Operators are symbols that perform operations on operands (variables or constants). They instruct the compiler to carry out arithmetic, relational, logical, assignment, or bitwise operations. Examples include arithmetic operators (+, -, *, /, %), relational operators, logical operators (&&, ||, !), assignment operator (=), and increment/decrement operators (++, --). For example, in c = a + b;, the symbols = and + are operators that assign and add values.

5. Punctuators (Special Symbols)

Punctuators are special characters used to separate or group different parts of a program and to define its structure. They include symbols such as semicolon ;, comma ,, parentheses ( ), braces { }, square brackets [ ], and the preprocessor symbol #. For example, the semicolon ; marks the end of a statement, parentheses ( ) are used in function calls like printf(), and braces { } define the body of a function or loop.

Видео Tokens in C Programming канала ThInKs We KnOw
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять