Programming Tutorials

The C Character Set

By: Nithya Suresh in C Tutorials on 2008-07-05  

A character denotes any alphabet ,digit or symbols to represent information.The following are the valid alphabets, numbers and special symbols permitted in C 

Numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 

Alphabets: a, b, ….z

                  A, B, ……...Z 
 

Arithmetic Operations: +, -, *, /, %(Mod) 

Special Characters:

                               

( ) { } [ ] < >
= ! $ ? . , : ;
& | ^ ~ ` #
\ blank - _ / * % @
 
 

CONSTANTS, VARIABLES AND KEYWORDS

A ‘constant’ is an entity that does not change, but a ‘variable’ as the name suggests may change. We do  a number of calculations in a computer and the computed values are stored in some memory spaces. Inorder to retrieve and re-use those values from the computer’s memory locations they are given names. Since the value stored in each location may change, the names given to these locations are called as ‘variable names’.

Constants:

There are mainly three types of constants namely: integer, real and character constants.

Integer Constants:

The integer constants

  • Whole Numbers
  • Eg. 25, 35, -25, -46
  • Computer allocates only 2 bytes in memory.
  • 16th bit is sign bit. (if 0 then +ve value, if 1 then –ve value)

                 

1       1       1       1        1       1       1      1       1        1       1        1       1       1        1

214        213       212         211        210        29         28      27      26        25          24           23         22           21           20 

= 1*1  +  4*1  +  8*1  +  16*1  +  32*1  +  64*1  + 128*1  +  256*1  +  512*1  +  1024*1  +  2048*1  +  4096*1  +  2*1  +  8192*1  +  16284*1 

=  32767 (32767 Bits can be stored for integer constants)

  • 32768 is negative
  • -32767 is minimum
 

       (i) Decimal Integer Constant:

  • 0 to 9
  • E.g: 49, 58, -62, … (40000 cannot come bcoz it is > 32767)

        (ii) Octal Integer Constant:

  • 0 to 7
  • Add “0” before the value.
  • Eg.: 045, 056, 067
 

        (iii) Hexadecimal Integer:

  • 0 to 9 and A to F
  • Add 0x before the value
  • E.g: 0x42, 0x56, 0x67
 

REAL CONSTANTS:

The real or floating point constants are in two forms namely fractional form and the exponential form.

A real constant in fractional form must:

  • Have at least one digit
  • It must have a decimal point
  • Could have positive or negative sign(default sign is positive)
  • Must not have commas or spaces within it
  • Allots 4 bytes in memory

Ex:  +867.9, -26.9876, 654.0 

In exponential form, the real constant is represented as two parts. The part lying before the ‘e’ is the ‘mantissa’, and the one following ‘e’ is the ‘exponent’.

The real constant in exponential form must follow the following rules:

  • The mantissa part and the exponential part should be separated by the letter ‘e’
  • The mantissa may have a positive or negative sign(default sign is positive)
  • The exponent must have at least one digit
  • The exponent must be a positive or negative integer(default sign is positive)
  • The range of real constants in exponential form is -3.4e38 and -3.4e38

Ex:  +3.2e-4,  4.1e8,  -0.2e+4,  -3.2e-4 

CHARACTER CONSTANTS

A character constant is an alphabet, a single digit or a single special symbol enclosed within inverted commas. The maximum length of a character constant can be 1 character. Allots 1 byte of memory

Ex:  ’B’,  ’l’,    ’#’ 

Types of C Variables

Variable names are names given to locations in the memory. These locations can contain integer, real or character constants. An integer variable can hold only an integer constant, a real variable can hold only a real constant and a character variable can hold only a character constant.  

Rules for Constructing Variable Names

A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compilers allow variable names whose length could be up to 247 characters.

  • The first character in the variable name must be an alphabet
  • No commas or blanks are allowed within a variable name.
  • No special symbol other than an underscore (as in net_sal) can be used in a variable name.

Ex.: si_int

e_hra

pod_e_81

C compiler makes it compulsory for the user to declare the type of any variable name that he wishes to use in a program. This type declaration is done at the beginning of the program. Following are the examples of type declaration statements:

Ex.: int si, e_hra ;

float bas_sal ;

char code ;

Since, the maximum allowable length of a variable name is 31 characters, an enormous number of variable names can be constructed using the above-mentioned rules. It is a good practice to exploit this enormous choice in naming variables by using meaningful variable names.  

C Keywords

C makes use of only 32 keywords or reserved words which combine with the formal syntax to the form the C programming language. Note that all keywords in C are written in lower case. A keyword may not be used as a variable name.

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 
 
 






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in C )

Latest Articles (in C)