C-Programming

Introduction to C programming language

C seems a strange name for a programming language but this strange sounding language is one of the most popular computer language today because it is s structured, high level, machine independent language. It allows software developers to develop programs without worrying about the hardware platforms where they will be implemented.

The root of all modern language is ALGOL, introduced in the early 1960s. ALGOL gave the concept of structured programming to the computer science community. In 1967, Martin Richards developed a language called BCPL (Basic Computer Programming Language) primarily for writing system software. In 1970, Ken Thompson created language using many features of BCPL and called simply B.

C was evolved from ALGOL, BCPL and B by Dennis Ritchie (father of the C language) at Bell Laborites in 1972. C uses many concept of this programming language and added the concept of data types and other powerful features. Since it was developed along the UNIX operating system, it is strongly associated with UNIX. 

 

Reasons behind the popularity of the C-programming:

Due to the following characteristics of C programming language, we need this programming language:

  1. Flexibility nature:

C program is a flexible language because it includes only the words of the English language which can be easily understood by the users. The meaning of words (identifier in C) of this language has the same meaning as our daily life. Due to this we can understand the meaning of the every instruction (statement) given to the computer.

  1. Portable language/ Machine independent language:

Many programs written in one language run in one computer but may not run in other computer. But the program written in C language can run in any computer with little or no modifications on the program. This nature is called portability. Languages which depend upon the machine or computer system are called machine dependent language. Since C is machine independent language hence C program can be written in any computer system.

  1. Easy to lean and understand:

Since C uses all English words, therefore it is easy to learn and understand the c program.

  1. Modular/ Structured Programming language:

In C programming a complex or long program can be divided into many sub-programs which are called module or functions. Each module or function does the coherent work of the main program. Due to this the understanding of the program will be very easy. Also the program will very efficient. This is the most important feature of the C language.  

  1. Procedure oriented programming language:

This programming language only emphasize on the logic of the program used for solving the problem rather than the object. This means it only gives rise in the procedure of the programming.

What is compiling and compiler?

 

          Since computer can understand only binary language which includes only 0 and 1(i.e. either true or false). And the program that we write in the computer is not in the form of binary format. Therefore to make the program understandable by the computer, it should be first converted into machine language (binary language). The language translator which translates or converts the program written in high level language i.e. language that can understand by the human into the machine language is called compiler. Compiler is also a program or software.

          The process of converting or translating the program code written in high level language into the machine level language is called compiling. The program code is also called source code and the machine code called as object code.

The compilation process can be easily understood by the following figure:

                                                       Fig.: compilation process

 

 

                                                       Source code:

Program written in a particular programming language in its original form is called source code (program). The word source differentiates code from various other forms that it can have (for example, object code and executable code). To execute the program, however, the programmer must translate it into machine language. The compiler translates the source code into a form called object code. Source code is the only format that is readable by humans. When we purchase program, we usually receive then in their machine language format. This means that we can execute then directly, but cannot read or modify them.

                                            Object code:

Object code is the code produced by a compiler. Object code is the same as or similar to a computer’s machine language. The final step in producing an executable program is to transform the object code into machine language, if it is not already in this form. A program called linker does this job.

Basic structure of the C program

Documentation section
Linker section
Macro definition section/ definition section
Global variable declaration section
Global function declaration section
 main( ) function

declaration part;
execution part;

 

 

{       

 

 

}

 

Function definition section

                      

 

 

In this we study the sequence of the instructions to be written in any C program. For more clearly, we study about which section is to come first and which is supposed to be the last. In general all C programs have seven sections as shown in the table above in the sequence which are described in short.

  1. Documentation section:

In this section we write the question or the problem i.e. topic. This is not executable statement on the c program. This line remains in the program as comment line where we can write comment about the program.

  1. Linker section:

This line starts with #include which is called directive. It is not the part of the actual program. It is used as a command to the compiler to direct the translation of the program. The directives included in the program is called header file (where the meaning of library functions are written). For example:

#include<stdio.h>

#include<conio.h>

#inlcude<string.h>

#include<math.h>

  1. Definition section:

In this line we define the macro (constant or some short expression). For example:

 #define PI  3.1416

#define sum(a+b)       

  1. Global variable declaration:

The variable which can use any function of the program is called global variable. If a variable is to be declared globally then we should declare them just below the definition section or just above the user defined function declaration.

  1. Global function declaration:

Those functions or modules which can be called by any function of the program are called global function. Most of the books combine these two sections: global variable declaration and global function declaration as a single section because both section are declaration sections.

  1. main( ) Function:

                   This is the entry point of any program i.e. the execution of any program starts from this point. Main ( ) function is also a user defined function but main ( ) function and other user defined functions are difference from each other. The difference between main ( ) function and other function will study in later in the chapter FUNCTIONS.

                   In consists of two parts:

  1. declaration part
  2. Execution part.

The part of the main function where we declare the variable and function is called declaration part. The variable declared inside the main function is called local variable which can used only by main function. The declaration of any variable or function should be done before use them and above the execution part. The section in which we write executable statement or instruction to the compiler is called execution part. Actual body of the program is this execution part.

  1. Function definition section:

                   Once a function is declared and is to be used then the work of that function should be written. This is called function definition. The detail study in this topic, we will study in chapter FUNCTIONS.

Basic introduction on computer software and its types (Prev Lesson)
(Next Lesson) Programming tools
Back to C-Programming

No Comments

Post a Reply

Teacher
Bhim Gautam
Role : Lecturer
Read More
error: Content is protected !!