Monday, June 22, 2015

Getting Started With C

Learning C is just like learning any other language and is easier.Instead of straight away learning how to write programs,we must first know the Alphabets,numbers and special symbols which have been used in C,and then how with the help of these constants,variables and keywords are constructed and how are these combined to form an instructions.
You can best understand this with the help of below flow chart example:

Steps in learning English Language:

Alphabets->Words->Sentences->Paragraph.

Steps in learning C Language:

Alphabets                   Constants              
Digits                     -> Variables           -> Instructions  ->Program.
Special Symbols         Keywords

In C we have three types of Character Set:

Alphabets:                 A,B,C,............,Y,Z.
                                  a,b,c,................,y,z.
Digits:                       0,1,2,3,4,5,6,7,8,9

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

The alphabets,digits and special symbols when properly combined form constants,variables and keywords.

Constant: A constant is an entity that doesn't change.
Variable: A variable is an entity that may change.
Keyword:A keyword is a word that carries special meaning.


Constants are further classified into two categories:
 (i)-Primary Constants.
(ii)-Secondary Constants.


Primary Constants->a:Integer Constant.
                                 b:Real Constant.
                                 c:Character Constant.
Secondary Constant->a:Array
                                    b:Pointer
                                    c:Structure
                                    d:Union
                                    e:Enum. etc.


In this  discussion we discuss only Primary Constants and rest later.

Rules For Constructing Integer Constants:

1- An Integer constant must have at least one digit.
2- It can be positive or negative.
3-If no sign precedes an integer constant,it is assumed to be positive.
4-No Commas or blanks are allowed with in it.
5-It must not have a decimal point.
6-The allowable range for integer type constant is:
        -2147483648 to +2147483647. for compilers like gcc,Visual Studio etc.
    and -32768 to +32767 for compilers like Turbo C++ etc.

eg:
     895
     -9645
    +789
      12

Rules For Constructing Real Constants:

These constants are also called as Floating Point Constants
The real constants can be written in two forms
Fractional Form and
Exponential Form.

Rules which we have to keep in mind while constructing these as in Fractional form:
1-It must have at least one digit and have a decimal point
2-It could either be positive or negative.
3-Default sign is positive.
4-No commas and blanks are allowed
Eg::
        +596.58
         36.25
         -0.28

In exponential form the real constant is represented as in two parts :The part appearing before 'e' is called mantissa where as part after 'e' is  called as exponent.Thus 0.000896 can be written in exponential Form as 8.96e-4.

Rules for exponential form is:
1-The two parts(Mantissa and Exponential)  must be separated by letter 'e' or'E'.
2-Default sign of Mantissa part and Exponent part is positive but it may have positive or negative           sign.    
3-The exponent must have at least one digit.
4-Range of real constants is -3.4e38 to +3.4e38 

Rules For Constructing Character Constants:

1-It is a single alphabet,single special symbol or a single digit enclosed within single inverted                commas.
2-Both commas should point to left i.e.'B' where as 'B` is invalid.

Eg:
      'S'
      'd'



--------------------------------------------------------------------------------------------------------------------------
In next post i will describe you about C variables and C keywords after that i will show you the programming portion of C.






No comments:

Post a Comment