Overview of C.

In this post we will be showing you some overview of C language.

  • History of C: -  
    • C was evolved from ALGOL(first computer language to use block structures), BCPL(Basic Combined Programming Language), and B by Denis Ritchie at the Bell Laboratories in 1972. It uses many concepts from these languages and added the concept of data types and other powerful features. Since it was developed along with the UNIX operating system, it is strongly associated with UNIX. 
    • To assure that C language remains standard, in 1983, ANSI(American National Standard Institute) appointed a technical committee to define a standard for C. The committee approved a version of C in December 1989 which is now known as ANSI C. It was then approved by ISO in 1990. This version is also referred to as C89.

  • The #include Directive
    • As mentioned earlier , C program are divided into modules or functions. Some functions are written by users like you and me, and others are stored into the C library. Library functions are grouped category-wise and stored in different files known as header files. If we want to access the functions stored in the library, it is necessary to tell the compiler about the files to be accessed.
    • This can be done by a simple syntax which you guys will get use to it.

  • Basic Structure of C programs: -
    • A C program can be viewed as a group of building blocks called functions. A function is a subroutine that may include one or more statements designed to perform a specific task. To write a c program, we first create functions and then put then put them together. A C program may contain one or more section as shown below
*********************************************************************************
Documentation Section
Link Section
Define Section
Global Declaration Section
main() Function Section
{
       Declaration part;
       Executable part;
}
                                                                                                                                                                   
Subprogram Section
User defined Functions...
*********************************************************************************

    • The Document Section consists of a set of comments lines giving the name of the program, the author and the other details, which the programmer would like to use later. 
    • The link section provides instruction to the compiler to link functions from the system library.
    • The Define section defines all the symbolic constants.
    • There are some variables which are used over entire program including main and other functions , they are declared in Global Declaration section.
    • Every C program must have a main() function section. This section contains two parts, declaration part and executable part. The declaration part declares all the variable(local variables) which are used in executable part. These two parts must appear between two braces. The closing braces is the  logical end of any function and ';' (semicolon) is the end of a statement , if not mentioned will give error.
    • The Subprogram section contains all the user-defined functions that are called in the main function. User-defined function are generally placed immediately after the main function, although they may appear in any order.

  • Sample Programs :- 
    • Printing a message :- 

                  /*This is a sample program*/

                 #include<stdio.h>
                void main()
                                        {
                                           /*printing begins*/
                                           printf("Hello world");
                                           /*printing ends here*/
                                         }

    • This program will produce this output 'Hello World' when executed.
    • Let us take a close look at the program
      • The first line is from the documentation section.(click on the link to understand what is The link Section briefly)
      •  It is consisting of comments enclosed in '/*' and '*/', comments to placed in a single line can also be place by just putting '//' at the beginning of the comment. Comments can not be nested 
        • for e.g /*comments/*comment2*/comment3*/
        • Here compiler ,after reading the start of comment '/*' will only search for the end of comment and ignore all other things.'*/'
      • The second line is from the link section in which the header files are included(click on the link to understand what is The link Section briefly)
      • The third line is of main() function section and the rest below it is the main function's content.

  • Adding two number

                  /*Program for Addition of two numbers */
                  main()
                            {
                              int number;
                              float amount;

                              number=100;

                              amount=30.75+75.35;
                              printf("%d\n",number);
                              printf("%5.2f",amount);
                            }
    • Now you can easily understand that which line is from which section of the structure of C program.
    • But there are few things new for you in this program, let us discus those things.
    • inside the main() function 'int' and 'float' are used to assign variables 'number' and 'amount'
    • 'int' and 'float' are a couple of inbuilt data types of C used in this program which will be discussed in later post.(link will be mention here when details will be posted)
    •  For just now keep in mind that 'int' data type has a memory storage of 2 bytes and it can only store decimal values, and 'float' data type has a memory storage of 4 bytes.
    • in the printf function '%d' is used to print a stored value of 'int' data type, similarly '%f' is used to store value of float variable, '%5.2' mean that maximum of 5 digit before floating point and 2 digit after floating point are allowed.

  • Executing a C program :-


    • Executing a program written in C involves a series of steps. These are: -
      1. Creating a program;
      2. Compiling the program;
      3. Linking the program with the functions that are needed from the C library; and
      4. Executing the program.

Comments

Popular posts from this blog

Windows phone Wifi connectivity problem.

Create Excel file using Java: Apache POI - PART - 2: Line Chart