In the context of programming languages, including C, tokens are the smallest individual units of a program. C programs are divided into tokens, and these tokens serve as the building blocks of the language’s syntax and structure. There are several types of tokens in C:
- Keywords: Keywords are reserved words that have predefined meanings in the C language. Examples include
if
,else
,for
,while
,int
,float
,char
, and so on. Keywords cannot be used as variable names or identifiers. - Identifiers: Identifiers are user-defined names used to identify variables, functions, or other entities in a C program. An identifier can consist of letters (both uppercase and lowercase), digits, and underscores, but it must start with a letter or an underscore. Examples of identifiers are
myVariable
,calculateSum
,MAX_VALUE
, etc. - Constants: Constants are fixed values that do not change during program execution. There are different types of constants in C:
- Integer Constants: These are whole numbers without decimal points. For example,
42
,-10
, or0
. - Floating-Point Constants: These are numbers with decimal points or in exponential form. For example,
3.14
or1.23e-5
. - Character Constants: These are individual characters enclosed in single quotes. For example,
'a'
,'7'
, or'%'
. - String Constants: These are sequences of characters enclosed in double quotes. For example,
"Hello, World!"
.
- Integer Constants: These are whole numbers without decimal points. For example,
- Operators: Operators perform specific operations on operands. C supports various types of operators, including arithmetic operators (
+
,-
,*
,/
,%
), assignment operators (=
,+=
,-=
,*=
,/=
), comparison operators (==
,!=
,>
,<
,>=
,<=
), logical operators (&&
,||
,!
), and more. - Punctuation Symbols: Punctuation symbols are used for grouping, separating, or terminating parts of the program. Examples include braces
{}
, parentheses()
, brackets[]
, commas,
, semicolons;
, and so on. - Special Symbols: Special symbols include specific characters or combinations that serve unique purposes in C. For example, the
#
symbol is used for preprocessor directives, such as#include
or#define
.
These are the basic tokens in the C programming language. By combining these tokens, programmers create meaningful statements, expressions, and constructs to build C programs.
Special characters in C:
In C programming, special characters are symbols or escape sequences that have specific meanings and functions within the language. These characters are used to perform various tasks, such as formatting output, representing control characters, and handling special situations. Here are some commonly used special characters in C:
- Escape Sequences:
\n
: Newline character\t
: Horizontal tab character\r
: Carriage return character\\
: Backslash character\"
: Double quotation mark character\'
: Single quotation mark character\0
: Null character
- Formatting Characters:
%d
: Integer format specifier%f
: Float or double format specifier%c
: Character format specifier%s
: String format specifier
- Arithmetic and Assignment Operators:
+
: Addition operator-
: Subtraction operator*
: Multiplication operator/
: Division operator%
: Modulus (remainder) operator=
: Assignment operator
- Comparison Operators:
==
: Equal to operator!=
: Not equal to operator<
: Less than operator>
: Greater than operator<=
: Less than or equal to operator>=
: Greater than or equal to operator
- Logical Operators:
&&
: Logical AND operator||
: Logical OR operator!
: Logical NOT operator
- Punctuation Symbols:
;
: Semicolon (statement terminator),
: Comma (separator for function arguments or list items).
: Member access operator (used for accessing structure or union members)->
: Pointer-to-member access operator (used for accessing structure or union members via pointers)
- Braces and Parentheses:
(
,)
: Opening and closing parentheses (used for function calls, expressions, and grouping){
,}
: Opening and closing braces (used for defining blocks of code)
These are some of the special characters in C programming. Understanding and using them correctly is important for writing valid and effective C programs.