An Introduction to C Programming Language

9 Min Read
Sample C Program

A basic command which is given to a computer to make it perform some task is called an instruction, and an organized list of such instructions which when executed causes the computer to run in predetermined manner is called program. A program consists of number of variables, functions, syntax etc. The phenomenon of writing such program is called programming.

Computer program has its own writing rules, called syntax. So, a computer programming language is standardized programming technique for explaining instructions for a computer. FORTRAN, C, C++, JAVA are some examples of more widely known programming languages.

Programming languages are categorized into two categories:

  • Low level Language
  • High Level Language

Low level language comprises of machine level language and assembly language which are very difficult to learn, so now days no program is written in low level language. One advantage of low languages is that they are faster than high level languages.

The syntax of high level programming language resembles human language. Hence, they are in wide use and can be learned easily. C, C++, JAVA, FORTRAN are some examples of high level programming language.

The program written in high level programming language is commonly known as ‘Source Code’ which is readable by human. In this article we are going to talk about C programming language – its history, features, the procedure to write a program in C, and more.

About C Programming Language:

C is a high level programming language developed in 1972 at AT & Bell Laboratory, USA by Dennis Ritchie. C became popular within the short period of time. In the late seventies this high level language started replacing more familiar languages of that time like ALGOL, PL/I etc.

This was possibly because C as a high level language is reliable, simple and easy to use and learn. Further, since C has been a platform for learning other high level languages. No one can learn C++, C#, JAVA etc without knowing the basics of C.

Writing a Program in C:

Writing a program in C language consists of the following sequences:

1. Understanding and Recognition of the Problem

Before writing code in C or any other programming language, the programmer must understand the problem. He/She must know what actually the program is going to be built for. The programmer must be familiar with the problem and its solution techniques.

2. Preparation of Algorithm

Algorithm is the collection of different steps which will be followed by computer when the code is executed. Algorithm is written in human language, generally in English. If the programmer has understood the problem, he can easily prepare the algorithm. Writing algorithm the is most important step in C programming.

3. Drawing Flowchart

Flowchart for Do-While loop

Flowchart is simply a graphical representation of algorithm. Flowchart shows how the control flows when the program is executed. There are some special symbols in flow chart which have specific significance.

For instance, an oval is used to represent start or stop, an arrow is used to represent flow direction, a rectangle for processing, a parallelogram for input and output, a diamond for decision making, a circle is used as connector.

Problems can be easily and effectively analyzed by using flowchart. (The above-mentioned is a flowchart for do-while loop.) Find more algorithms and flowcharts

4. Writing Pseudo Code

Pseudo code is conversion of algorithm into semi-source-code. While writing pseudo code in C, the steps followed by the computer are written in C language, but it is not mandatory to follow the exact syntax of C.

5. Writing Source Code

Source Code, also known as program, is the target of a programmer. In C programming, source codes are written in IDE, Integrated Development Environment. Code::Blocks and Turbo C are the most widely used IDEs for C.

A source code comprises of header file, functions, variables, constants, identifies, array, structures etc. arranged in such away that it follows C’s syntax and executes to perform the desired task. The basic physical structure of a C program is given below:

#include<header file>
#include<header file2>
    global variable declaration and definition
    function declaration and definition
    main()
    {
        Variable declaration;
        Variable input; // comments
        Function calling;
        Printing output;
    }

Each statement in C program must be terminated with semicolon(;), and all the program must have at least one function of name main(). Scope of function is within the curly braces ({}).

6. Running the Program and Debugging

After coding is finished it needs to be run in IDE. The program may have number of errors which are shown by IDE as error messages; the correction of such errors is commonly known as debugging. Debugging is an essential step in C or any other programming language. The conversion of source code into object or machine code is called compilation.

7. Program Documentation

Program documentation is the description of program written within the code as comment. In program documentation, function and significance of various functions and variables used in the program are commented as single line or multiple line comments.

Some Features of C Language:

  • C is a powerful, flexible, portable and elegantly structured programming language. The wide popularity and use of C programming is probably due to the fact that it is a robust high level language whose rich and powerful set of in-built functions and several operators can be used to write simple to complex programs. Therefore, it is well suited for writing both business packages as well as system software. But the program written in C are relatively heavier.
  • C programming source codes are highly portable. This means C programs written for one computer can be run on another with little or no modification. Portability is important if one plans to use a new computer with a different operating system.
  •  C programming as a high level language can be easily adopted in structured programming, thus requiring the user to think of a problem in terms of function modules or blocks. A proper collection of these modules would make a complete program. This modular structure makes program debugging, testing and maintenance easier.
  •  Another important feature of C programming language is its ability to extend itself. A C program is basically a collection of functions that are supported by the C library. We can continuously add our own functions to the C library. With the availability of a large number of functions the programming task becomes simple.

Every programmer needs to have a sound knowledge of C programming to understand the basics like how the software in their computers and cells are developed and how they work. Furthermore, C has been an effective platform for learning higher level programming languages like C++, C#, JAVA, and more.

TAGGED:
Share This Article
1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version