Featured Posts

The fundamentals of C Programming.

     Communicating with a computer involves speaking the language the computer understands, which immediately rules out English as the language of communication with computer.  However, there is a close analogy between learning English language and learning C language.  The classical method of learning English is to first learn the alphabets used in the language, then learn to combine these alphabets to form words, which in turn, are combined to form sentences and sentences are combined to form paragraphs.  Learning C is similar and easier.  Instead of straight-away learning how to write programs, we must first know what alphabets, numbers and special symbols are used in C, then how using them constants, variables and keywords are constructed, and finally, how are these combined to form an instruction.  A group of instructions would be combined later on to form a program.

The C character Set

     A character denotes any alphabet, digit or special symbol used to represent information.  For example :

Alphabets : A,B,C.........X,Z. or a,b,c........x,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 form constants, variables and keywords. A constant is an entity that doesn't change, whereas, a variable is an entity that may change.  In any program we typically do lots of calculations.  The results of these calculations are stored in computer's memory.  Like human memory, the computer's memory also consists of millions of cells.  The calculated values are stored in these memory cells. To make the retrieval and usage of these values easy these memory cells are given names.  Since the value stored in each locations may change the names given to these locations are called variable names. 

Types of C constants

     C constants can be divided into two major categories :
(a) Primary Constants
(b) Secondary Constants

Rules for constructing Integer Constants :

  1. An integer constant must have at least one digit.
  2. It must not have a decimal point.
  3. It can be either +ve or -ve.
  4. If no sign precedes and integer constant, it is assumed to be positive.
  5. No commas or blanks are allowed within an integer constant.
  6. The allowable range for integer constants is -32768 to 32767.
     The range of an Integer constant depends upon the compiler.  For a 16-bit compiler like Turbo C or Turbo C++ the range is -32767 to 32767.  For a 32-bit compile, the range would be even greater.
Example : 896

Rules for constructing Real Constants :

     Real constants are often called Floating Point constants.  The real constants could be written in two forms- Fractional form and Exponential form.
Following rules must be observed while constructing real constants expressed in fractional form :
  1. A real constant must have at least one digit.
  2. It must have a decimal point.
  3. It could be either positive or negative.
  4. Default sign is positive.
  5. No commas or blanks are allowed within a real constant.
Ex:  +356.56

Exponential form of representation of real constants is usually used if the value of the constant is either too small or too large.  It, however, doesn't restrict us in any way from using exponential form of representation for other real constants.  In exponential form of representation the real constant is represented in two parts.  The part appearing before 'e' is called mantissa, whereas the part following 'e' is called exponent.  Thus 0.000586 can be represented in exponential form as 5.86e-4

Post a Comment


www.posthatke.com. Powered by Blogger.

Google+ Followers

Copyright © www.posthatke.com | Blogger Templates | Designed By posthatke.com