Skip to content

Let us start with C Programming

In this article we will have a look at the C programming, why should we learn it, different features of C and basic structure of C programming .

Introduction to C Programming language

C has probably been the most commonly and known programming language. It is a procedural programming language which was developed by Dennis Ritchie at Bell Telephone Laboratories in 1972. It was developed so that it could be used in UNIX operating systems.

C language can be defined in the following ways:

1. Mother language

C is being considered as the mother language for almost all the modern programming languages as most of the compilers, JVM, Kernels, etc. are also being written in C language. C also shares its syntax and core concepts like array, strings, functions, file handling, etc. with the programming language like Java, C++, etc.

2. System Programming Language

System programming language is used for creating system software (or OS). C language can be used to do the low-level programming (ex. Kernel and drivers). It is being generally used to create hardware devices, kernels, drivers, OS, etc.

This is the main reason C is the primary choice when programming an embedded system.

3. Procedural Programming Language

Procedural Language specifies a series of steps for the program to solve the different kinds of problem. Hence, we can say that procedural language breaks the program into functions, data structures, etc.

It is so because before using the variables and functions in the program, we need to define/declare them in the start.

We can even say that C is a structural programming language, as we can break the program into different parts using functions. This makes the program easier for understanding, modifying and debugging. (Structural Programming is considered as a sub-set of procedural language)

4. Mid-Level Programming Language

It is considered as mid-level programming language as it supports the features of both low-level and high-level languages.

At some instances, C is considered as low-level language as it is used to program the kernel and also supports pointer arithmetic.

And at some instances C is considered as high-level language as it is portable, i.e. machine independent and easy to understand.

Hence, we call it mid-level language.

Why Should we learn C Programming language?

Reasons behind learning C are:

  1. It is the language that starts from the scratch and consist of all the foundational concepts on which today’s modern programming language rely on. Even libraries of some modern languages are written in C.
  2. Several languages like Java, C++ share same programming concept and syntax. So, learning these languages after C helps us in understanding it in a better way.
  3. C doesn’t hide the complexities and capabilities of the machine underneath. So, the programmer gets a lot of power once you know what can be done with the machine.
  4. C is very fast in terms of the execution time. Programs which are written in C executes much faster than other programming language.
  5. As C is procedural code, it teaches us to write the code in an imperative paradigm.
  6. C isn’t an OOP language, so we don’t have to deal with inheritance and polymorphism which makes are code complicated and heavy.
  7. For writing a maintainable code in C needs coding discipline because finding and correcting a missing or additional semicolon can be frustrating and time consuming. Hence, C teaches coding discipline.
  8. Helps to understand the fundamentals of Computer Theories. Most of the theories related to computers like Computer Networks, Compiler Designing, Computer Architecture, Operating Systems are based on C programming language and requires a good knowledge of C programming if you are working on them.

Features of C language

    1. Simple to use as it provides a structured approach and also provides rich set of library functions, data-types, etc.
    2. It is machine independent as it can be executed on different machines with some machine specific changes.
    3. Because of its structured approach we can break the program into different parts using functions which helps us in understanding, modifying and debugging the code. Functions also provides with code reusability .
    4. C provides us with many in-built libraries, which makes the development fast.
    5. As C supports dynamic memory allocation.
    6. C has fast compilation and execution time as it has less in-built functions and hence, lesser overheads.
    7. C provides with a feature which enables us to directly interact with the memory using pointers. We use pointers for memory, structures, array, functions, etc.
    8. C allows recursion (i.e. calling function inside a function). This provides with code reusability for every function and it also enables us to use back-tracing approach.
    9. C language is extensible as it can easily adopt new features.

Basic Structure of C Programming

After the above discussion, let’s have a look at basic structure of a C program. By structure, it is meant that the program should be written in this structure only. Writing in some other structure might lead to Compilation Error.

  1. C programming - structureHeader File Inclusion: First and foremost component in the structure is the inclusion of Header file in a C program. A header file is a file which has an extension .h which contains the C function declaration and macro definitions which has to shared between several source files. Commonly used header files in C are:
    1. stdio.h – Defines the core input and output functions
    2. string.h – Defines string handling functions
    3. math.h – Defines common mathematical functions
    4. stdlib.h – Defines general utility functions
  2. Main Method Declaration: Next part of C program is to declare the main() function.
  3. Variable Declaration: Next part of C program is the variable declaration, which is used to in the function. In C, we cannot use any variable without declaring it and we also need to declare the variable before using it/doing an operation on it.
  4. Body: Next part of C program refers to the operations that are supposed to be performed in the functions. The operation can be anything like manipulation, searching, sorting, printing, etc.
  5. Return Statement: It is the last part of any C program. This statement refers to returning the values from a function. The return statement depends on the type of function.

Now as we have seen the basic structure of C programming, lets write our first program:

Input:

#include <stdio.h>
int main()
{
    printf("Hello World");
    return 0;
}

Output:

 

 

 

Let’s analyze the above code line by line:

Line-1: [#include <stdio.h>] In C program, lines which start with # are processed by preprocessor which is a program that is invoked by the compiler. This lines tells the C compiler to include the header file before the actual compilation takes place.

Line-2: [int main()] The execution in C begins from this line. The int written before main indicates the return type of main(). The value returned indicates the status of program termination.

Line-3 and 6: [ { … } ] In C programming, curly brackets are used to define the scope and are mainly used in functions and control statements like if, else, loops.

Line-4: [printf(“Hello World”);] printf() is a standard library function to print on standard output. Semicolon at the end of line indicates the end of statement.

Line-5: [return 0;] It returns the value from main(). It is used to see the status of termination. Value 0 is used as it typically means successful termination.

Leave a Reply

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