Character Set
Character Set
1. Character Set in C
The character set in C defines the valid characters that can be used in a program. These
characters are classified as follows:
Types of Characters:
1. Letters:
o Uppercase: A-Z
o Lowercase: a-z
2. Digits:
o 0-9
3. Special Characters:
o ~, !, @, #, $, %, ^, &, *, (), -, +, =, {}, [], :, ;, '', "", <, >, /, \, ., ,, |, _, ?
4. Whitespace Characters:
o Blank spaces, tabs (\t), newlines (\n).
Usage:
The character set forms the foundation for constructing tokens, identifiers, and other program
elements.
2. C Tokens
Tokens are the smallest individual units of a C program. They are the building blocks of the
program.
Types of Tokens:
1. Keywords: Reserved words that have predefined meanings in C (e.g., int, return).
2. Identifiers: Names used for variables, functions, arrays, etc.
3. Constants: Fixed values in the program, such as numbers (10, 3.14) or characters ('A').
4. Strings: Sequence of characters enclosed in double quotes (e.g., "Hello").
5. Operators: Symbols that perform operations on variables and values (e.g., +, -, *, /, =).
6. Special Symbols: Characters with specific meanings (e.g., ;, {}, []).
7. Separators: Characters used to separate statements or elements, such as commas (,) and
semicolons (;).
3. Keywords in C
Definition:
Keywords are reserved words that have a specific meaning in the C language. They cannot be
used as identifiers.
List of C Keywords:
Important Notes:
4. Identifiers in C
Definition:
Identifiers are names used to identify variables, functions, arrays, or other user-defined elements.
1. Allowed Characters:
o Only letters (A-Z, a-z), digits (0-9), and underscores (_).
2. First Character:
Must be a letter or underscore.
o
o Cannot be a digit.
3. No Spaces:
o Identifiers cannot have spaces or special characters.
4. Case Sensitivity:
o Identifiers are case-sensitive (variable and Variable are different).
5. Keyword Restriction:
o Keywords cannot be used as identifiers.
Examples:
Example Program:
#include <stdio.h>
int main() {
// Example of identifiers
int num1 = 10; // num1 is an identifier
int num2 = 20; // num2 is an identifier
int sum; // sum is an identifier
// Process
sum = num1 + num2;
// Output
printf("Sum: %d\n", sum);