Character set blog

 Character Set

The various categories of characters are called the character set. In C, the

characters are grouped into the following categories:

a) Letters:

a. Uppercase: A………….Z

b. Lowercase: a…………..z

b)Digits:

a. All digits: 0…………..9

c) Special Characters, such as

a. , Comma

b. . Period

c. ; Semicolon

d. : Colon

Tokens in C is the most important element to be used in creating a program in

C. We can define the token as the smallest individual element in C.

C tokens are the basic building blocks in C language which are constructed

together to write a C program.

C token are of six types.

o Keywords (eg. int, while)

o Identifiers (eg. main, total)

o Constants (eg. 10, 20)

o Strings (eg. “total”, “heta”)

o Special Symbols (eg. (), { })

o Operators (eg. +, -, *, / )

Keyword and Identifier

In 'C' every word can be either a keyword or an identifier.

Keywords:

Keywords have fixed meanings, and the meaning cannot be changed.

They act as a building block of a 'C' program. There are a total of 32 keywords in 'C'.

Keywords are written in lowercase letters.

Identifiers:

An identifier is nothing but a name assigned to an element in

a program.

Example:

name of a variable, function, etc.

Identifiers are the user-defined names consisting of 'C' standard character set.

As the name says, identifiers are used to identify a particular element in a program.

Each identifier must have a unique name.

Following rules must be followed for identifiers:

 The first character must always be an alphabet or an

underscore.

 It should be formed using only letters, numbers, or

underscore.

 A keyword cannot be used as an identifier.

 It should not contain any whitespace character.

 The name must be meaningful.

 Only first 31 characters are significant.

Constant

Constants are the fixed values that never change during the

execution of a program. Following are the various types of constants:

1) Integer constants

An integer constant is nothing but a value consisting of digits or

numbers. These values never change during the execution of a program.

There are 3 types of integer constant.

a) Decimal Integer

b) Octal Integer

c) Hexadecimal Integer

Decimal Integer:

Consist of a set of digitals from 0 to 9, presented by an

optional + or – sign

Example:

o 123

o -321

o 0

o 89765

 Octal Integer:

Octal integer consists of a set of digits from 0 to 7, with

leading 0.

Example:

o 037

o 0

o 043

o 0551

Hexadecimal Integer:

Hexadecimal integer consists of sequence of digits preceded

by 0x or 0X is considered as hexadecimal.

They may also include letters from A to F or from a to f. the

letters represents the numbers from 10 to 15.

Example:

o 0X2

o 0x9F

o 0Xbcd

o 0x

2) Real constants

Real constants are used to represent quantities that are very

continuous such as distances, temperature etc.

These quantities are represented by numbers containing fractional

parts.

Example:

0.00832

-0.75

33.337

3) Single character constant

A single constants contains a single character enclosed within a

pair of single quote marks.

Example:

„5‟

„X‟

„;‟

4) String constant

A string constant contains series of characters enclosed within a

pair of double quote marks.

Example:

“Hello !”

“1234”

5) Backslash character constants

Constants Meaning

„\a‟ Audible alert

„\n‟ New line

„\?‟ Question mark

Variables:

A variable is a data name that is used to store data values. A variable

may take different values at different times during execution.

Some examples are average, heights, class_strength.

Rules of creating variable:

Variable names may consist of letters, digits and the underscore character,

subject to following conditions.

 Must consist of only letters, digits and underscores.

 First character must be an alphabet. Some system permits underscore as

the first character.

 31 characters are permitted. But only the first 8 characters are

significant.

 Uppercase and lowercase are significant.

 It should not be a keyword.

 White spaces are not allowed.

Comments

Popular posts from this blog

Computer programming

Functional units of computer

Compiler and interpreter