C Assingment
C Assingment
ASSINGMENT-2
CHARACTERS IN “C”
Character Set includes a set of valid characters we can use in our program in different
environments. C language has broadly two character sets.
• Source Character Set (SCS): SCS is used to parse the source code into internal
representation before preprocessing phase. This set includes Basic Character Set
and White-space Characters.
• Execution Character Set (ECS): ECS is used to store character string constants.
Other than Basic Character Set, this set contains Control Characters and Escape
Sequences.
Character Set in C
In C, the character set used to represent characters in source code is based on the ASCII
(American Standard Code for Information Interchange) character set. The ASCII character
set includes the following elements:
1. Alphabetic Characters (A-Z, a-z): These represent both uppercase and lowercase
English letters. For example, 'A' to 'Z' and 'a' to 'z'.
2. Digits (0-9): These represent numeric characters. For example, '0' to '9'.
3. Special Characters: These include various special characters used in
programming and text processing. Some common special characters include:
• Arithmetic Operators: +, -, *, /, %
• Relational Operators: <, >, ==, !=, <=, >=
• Logical Operators: &&, ||, !
• Punctuation: ;, :, ,, ., ?, !
• Brackets and Parentheses: (, ), [, ], {, }
• Quotes: ', "
• Backslash: \
• Ampersand: &
• Dollar Sign: $
• Hash or Pound Sign: #
4. Whitespace Characters: These include space (' '), newline ('\n'), and form feed ('\f').
These characters are used for formatting and layout in code and text.
5. Control Characters: These include non-printable characters like the escape
character ('\e') and others used for control and formatting, such as '\b' (backspace),
'\t' (tab), and '\n' (newline).
6. Escape Sequences: C allows you to use escape sequences to represent
characters that are difficult to type or invisible. For example, '\n' represents a
newline character, and '\t' represents a tab character.
7. Extended Characters: C also includes characters beyond the ASCII set, especially
for international character encoding. These include characters with accents,
diacritics, and symbols from various languages.
• Digits: Digits in C are the numeric characters '0' through '9'. They are used to
represent numerical values and are fundamental for arithmetic operations,
numerical input, and output. Digits are represented as characters, but they can be
converted to integer values when needed.
• Special characters: In C programming language, generally, the special symbols
have some special meaning and they cannot be used for other purposes.
• Whitespace : Whitespace characters are used for formatting and layout in code
and text. They include space (' '), tab ('\t'), newline ('\n'), carriage return ('\r'), and
form feed ('\f').
TOKENS IN “C”
Tokens in C language are the minor elements or the building blocks used to construct or
develop together a C program. These tokens in C are meaningful to the compiler. The
online C compiler breaks a program into the possible minor units known as tokens and
proceeds further to the various stages of the compilation. Every meaningful character,
word, or symbol in this C program is a C token. Compiler groups together these characters
of the program into tokens.
Uses of Tokens in C
The following are the uses of tokens:
• Keywords
• Identifiers
• Constants
• Special Characters
• Strings
• Operators
Keywords: Keywords in C language are the collection of pre-defined or reserved words.
These are case-sensitive and written in lower cases. Their meaning and functionality are
already known to the compiler. There are 32 keywords in “c”.
IDENTIFIERS : Identifiers in C are short and informative names that uniquely identify
variables or function names.
These are user-defined words used for naming of functions, variables, structures, unions,
arrays etc. These can be composed of lowercase letters, uppercase letters, underscore or
digits, but the first character should be either an underscore or an alphabet.
CONSTANT: Constants are the variables whose values are fixed and can not be modified
during the execution of a program once they are defined. They are also known as literals.
Operators: Operators in C are special symbols used to perform specific functions, and
data items on which they are applied upon are known as operands. C language provides a
wide range of operators that can be classified into 6 types based on their functionality:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Other Operators