Character Set of C Language
The character set in C language refers to the valid set of characters that can be used in the source code. These characters include letters, digits, symbols, and special characters. They form the building blocks of C programs.
1. Letters
- Definition: The alphabetic characters used in C.
- Includes:
- Uppercase Letters:
A, B, C, ..., Z
- Lowercase Letters:
a, b, c, ..., z
- Uppercase Letters:
2. Digits
- Definition: Numeric characters used in the program.
- Includes:
- Digits:
0, 1, 2, ..., 9
- Digits:
3. Special Characters
- Definition: Characters with special purposes in the C language.
- Includes:
- Usage:
+
,-
,*
,/
: Arithmetic operators.{}
,[]
,()
: Braces and brackets.;
: Statement terminator.&
: Address operator.
4. White Space
- Definition: Characters used for spacing in the code to improve readability.
- Includes:
- Space (
- Tab (
\t
) - Newline (
\n
)
- Space (
5. Escape Sequences
- Definition: Special character combinations used to represent non-printable or special characters.
- Examples:
Escape Sequence Description \n
Newline \t
Horizontal Tab \\
Backslash \'
Single Quote \"
Double Quote \0
Null Character
6. Symbols
- Definition: Characters used for specific meanings in programming.
- Examples:
- Operators:
+
,-
,*
,/
,%
, etc. - Comparisons:
>
,<
,>=
,<=
,==
,!=
- Assignment:
=
- Operators:
7. Constants
Although not characters, constants (like 123
, 'A'
, or "Hello"
) are formed using the character set.
Summary Table
Category | Examples |
---|---|
Letters | A, B, ..., Z , a, b, ..., z |
Digits | 0, 1, 2, ..., 9 |
Special Characters | ! , @ , # , $ , ^ , & , etc. |
Escape Sequences | \n , \t , \\ , \' , etc. |
White Space | Space, Tab, Newline |
This character set forms the foundation for writing all C programs!
C Tokens
In the C language, tokens are the smallest units or building blocks of a program. A token is a meaningful element that the compiler recognizes during the compilation process. C has six types of tokens:
1. Keywords
- Definition: Reserved words in C that have predefined meanings and cannot be used as variable names or identifiers.
- Examples:
- Purpose: Used to define the syntax and structure of C programs.
2. Identifiers
- Definition: Names given to variables, functions, arrays, or other user-defined elements in a program.
- Rules:
- Must start with a letter or underscore (
_
). - Can contain letters, digits, and underscores.
- Cannot use C keywords.
- Must start with a letter or underscore (
- Examples:
3. Constants
- Definition: Fixed values that do not change during the execution of the program.
- Types:
- Integer Constants: Whole numbers (e.g.,
10
,-45
). - Floating-point Constants: Decimal numbers (e.g.,
3.14
,-0.005
). - Character Constants: Single characters enclosed in single quotes (e.g.,
'A'
,'3'
). - String Constants: Sequence of characters enclosed in double quotes (e.g.,
"Hello"
,"C Language"
).
- Integer Constants: Whole numbers (e.g.,
4. Operators
- Definition: Symbols that perform operations on variables and values.
- Types:
- Arithmetic Operators:
+
,-
,*
,/
,%
- Relational Operators:
<
,>
,<=
,>=
,==
,!=
- Logical Operators:
&&
,||
,!
- Bitwise Operators:
&
,|
,^
,~
,<<
,>>
- Assignment Operators:
=
,+=
,-=
,*=
,/=
- Others: Increment (
++
), Decrement (--
).
- Arithmetic Operators:
5. Special Symbols
- Definition: Symbols with special meanings in C programs.
- Examples:
- Usage:
- Parentheses
()
for function calls. - Braces
{}
for blocks of code. - Square brackets
[]
for arrays. - Semicolon
;
to terminate statements.
- Parentheses
6. Punctuation/Separators
- Definition: Characters that help separate statements or elements in a program.
- Examples:
Examples of Tokens in a Program
Summary of C Tokens
Token Type | Examples |
---|---|
Keywords | int , return , if , else , for , void |
Identifiers | main , a , sum , calculateArea |
Constants | 10 , 3.14 , 'A' , "Hello" |
Operators | + , - , * , / , < , > , && , = |
Special Symbols | {} , [] , () , # , ; , " |
Separators | ; , , , () , {} |
By understanding C tokens, you can write syntactically correct and meaningful C programs.