Saturday, December 5, 2009

Character Set of C

The characters that can be used to form words,numbers and expressions depend upon the computer on which program is run.The characters in C are grouped into the following categories:
1. Letters
2. Digits
3. Special Characters
4. White Spaces
The compiler ignores white spaces unless they are a part of string constant.White spaces may be used to separate words, but are prohibited between the characters of keywords and identifiers.

Alphabets A,B,...................,Y,Z.
a,b,.....................,y,z.
Digits 0,1,2,3,4,5,6,7,8,9.
Special symbols ~`!@#%^&*()_-+=\{}[]:;"'<>,.?/

Constants,Variables and Keywords:

The alphabets,numbers and special symbols when properly combined forms constants,variables and keywords.
- A constant is an entity that doesn't change whereas variable is an entity that may change.
- C constants are divided into two major categories:
(a) Primary Constants.
(b) Secondary Constants.
- Primary constants are further categorized as integer,real and character constants.
- Secondary constants are categorized as array,pointer,structure,union,Enum etc....

Rules for Constructing Integer Constants:

- An integer constant must have at least one digit.
- It should not have decimal point.
- can be either positive or negative.
- If no sign precedes an integer constant it is assumed to be positive.
- no commas or blanks are allowed within an integer constant.
- allowable range of integer constants are -32768 to 32767.

The range of the integer constants depend upon the type of compiler.

Ex: 426,+782,-8000 etc.....

Rules for Constructing Real Constants:

-
It should contain at least one digit.
- must have a decimal digit.
- could be either positive or negative.
- Default sign is positive(+).
-
no commas or blanks are allowed within an integer constant.

Ex: +325.34,426.0,-32.76 etc........

Rules for Constructing Character Constants:

-
It is a single alphabet, a single digit or a single special symbol enclosed within single inverted commas.Both the inverted commas should be left(i.e. ' ' ).For example, 'A' is a valid character whereas `A' is not.
- maximum length of a character constant can be 1 character.
Ex: 'A' 'I' '5' '='.

Variables:
An entity that may vary during the program is called a variable.

Rules for Constructing Variable Names:

-
A variable name is any combination of 1 to 31 alphabets,digits or underscores.
- The first character of variable name must be an alphabet or underscore.
- No commas or variables are allowed within a variable name.
- No special symbols other than underscore( _ ) can be used in a variable name.

Ex: si_int, m_hra,tot_class etc...............

C Keywords:

- Keywords are the words whose meaning has already been explained to the C compiler.There are 32 keywords available in C.The list of keywords present in are as follows:

auto
double
int
struct
break
else
long
switch
case
enum
register
typedef
char
extern
return
union
const
float
short
unsigned
continue
for
signed
void
default
goto
sizeof
volatile
do
if
static
while.

Compile vendors (like Microsoft, Borland etc....) provide their own keywords apart from the mentioned above.





No comments:

Post a Comment

Website Magazine