0% found this document useful (0 votes)
3 views4 pages

Character Set

The document outlines the character set, tokens, keywords, and identifiers in the C programming language. It details the types of characters used in C, defines tokens as the smallest units of a program, and lists reserved keywords that cannot be used as identifiers. Additionally, it explains the rules for naming identifiers and highlights the differences between keywords and identifiers.

Uploaded by

karan21439639
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Character Set

The document outlines the character set, tokens, keywords, and identifiers in the C programming language. It details the types of characters used in C, defines tokens as the smallest units of a program, and lists reserved keywords that cannot be used as identifiers. Additionally, it explains the rules for naming identifiers and highlights the differences between keywords and identifiers.

Uploaded by

karan21439639
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Character Set, C Tokens, Keywords, and Identifiers in C Language

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:

auto break case char const continue


default do double else enum extern
float for goto if int long
register return short signed sizeof static
struct switch typedef union unsigned void
volatile while inline restrict _Bool _Complex
_Imaginary _Alignas _Alignof _Atomic _Generic _Noreturn
_Static_assert _Thread_local

Important Notes:

 C keywords are case-sensitive.


 They should not be used as variable or function names.

4. Identifiers in C

Definition:

Identifiers are names used to identify variables, functions, arrays, or other user-defined elements.

Rules for Naming Identifiers:

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:

 Valid Identifiers: sum, total_marks, _temp, a1


 Invalid Identifiers: 123num (starts with digit), total marks (contains space), float
(keyword)

Differences Between Keywords and Identifiers

Aspect Keywords Identifiers


Predefined reserved words in User-defined names for program
Definition
C. elements.
Predefined/User-
Predefined by the language. Defined by the programmer.
defined
Examples int, if, return. age, student_name, calculate.

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);

return 0; // return is a keyword


}

You might also like