Character and Character Set 1 - What Is A Character, What Is Character Set in C Programming Define and Explain With Suitable Examples

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Here's a comprehensive explanation of characters and character sets in C programming:

Character:

● It's the basic unit of textual information in C programming.


● It represents a single letter, digit, symbol, or special character.
● It's stored as a single byte in memory, holding a numeric value corresponding to a specific
character in the character set.

Character Set:

● It's the collection of all valid characters that can be used in C programs.
● C supports two types of character sets:
1. Source Character Set (SCS):
■ The characters used to write the source code of a program.
■ It usually includes ASCII characters (128 characters) but can be extended.
2. Execution Character Set (ECS):
■ The characters a C program can process during execution.
■ It might include more characters than the SCS, depending on the system and
encoding.

Examples of Characters in C:

● Letters: 'a', 'B', 'Z'


● Digits: '0', '5', '9'
● Symbols: '+', '-', '*', '/'
● Special Characters: ' ' (space), '\n' (newline), '\t' (tab)

Typical SCS in C:

● Lowercase letters: a-z


● Uppercase letters: A-Z
● Digits: 0-9
● Punctuation marks: , . ; : ? ! " ' ( ) [ ] { }
● Arithmetic operators: + - * / %
● Assignment operator: =
● Relational operators: == != < > <= >=
● Logical operators: && || !
● Special characters: _ # $ & @ \ ~ ^ | `
● White space characters: space, tab, newline

Key Points:

● C internally represents characters using their ASCII codes (numeric values).


● You can use character literals (e.g., 'A') or escape sequences (e.g., '\n') to represent
characters in code.
● The ctype.h header provides functions for character classification and manipulation (e.g.,
isalpha, isdigit, toupper, tolower).

Example Code:

C
#include <stdio.h>

int main() {
char letter = 'C';
int ascii_code = letter; // ASCII code of 'C' is 67

printf("Character: %c\n", letter);


printf("ASCII code: %d\n", ascii_code);

return 0;
}

You might also like