Monday, June 29, 2015

What is a Program?

A program is a set of instructions  or we can say a sequence of instructions which are written to perform a specific task on computer.

Formation of a C program:

Lets take an example we have to print "WELCOME TO THE WORLD OF C PROGRAMMING"
the source code for the following is shown in the below



And the output for the corresponding source code is shown on black screen.




While Forming a C program we must have to keep the following points in mind:

1) Each of the instruction in C is written as a separate statement.
2) The instructions in a program must appear in the same sequence in which we wish to execute              them.
3) All instructions must be written in small letters .
4) C has no specific rules for the positioning at which statement has to be written. That's why it is            often called free-form language.
5) Each statement of the program must end with symbol ;
    As ;(semi colon) acts as a instruction terminator.


Now as you can see in above source code the body contains different types of parameters and each of them have specific functions so starting with the very first line i.e. Comments

1- Comments are basically used as the users point of view to decode the program
they are non executable instructions,the only use of these is to clarify the purpose of program or a particular statement.Though it is not necessary to write comments for each instruction.

Comments can be of two types 
a)Single line Comment : Comment can be written in single line as:
                                   
                                        //Hello reader welcome to c programming.
                                       //This is just a demo for you .
                                       //you can write anything here.

b)Multi line Comment: The comments written above can be split into a single multi line comment as:
                                   
                                   
                                     /* Hello reader welcome to c programming.
                                          This is just a demo for you .
                                          you can write anything here.  */

2-(#include<stdio.h>)
    This line is compulsory for including the library files of standard input /output functions.
    I will describe these later.

3-What is main().
    The main() function is the important part of the body of C program,All instructions should be              written under this function enclosed  within a pair of braces { }
     as shown in above source code

4-printf() and it's usage

    All output to screen is achieved using  readymade library functions.one such function is printf().
    syntax for using this function is:

                                                   printf("<Formatted string>",<list of variables>);


<Formatted string> can contain Message for user along with that format specifiers such as:
%f -for printing real values.
%d -for printing Integer values.
%c -for printing character values.

you can best understand this while writing further programs.

Note: printf() can not only print values of variables,it can also print the result of the valid expression.
         As expression is nothing but a valid combination of constants,variables and operators.
         Thus,2,8+2,a and a+b*c-d all are valid expressions.
         The result of these expression as shown below:
         printf("%d %d %d %d",2,8+2,a,a+b*c-d);

         COMPILATION AND EXECUTION:
Once program is framed you need to type it and instruct the computer to execute it .To type your C program you need editor.Once the program is typed it needs to be converted to a machine language(0s and 1s)i.e. binary language before machine can execute it.To carry out this we need Compiler.
There are several vendors who provides us Integrated Development Environment (IDE) which consist of an Editor as well as the Compiler.
One such IDE is Turbo C/C++
you can download the software by clicking here.