Introduction to C Language

C is an object oriented programming language. This is probably what you've read in those Computer Science books in school. But what does that mean?

Introduction to C
Introduction to C

Naturally, for a fresh lad who is into programming, such a heavy statement won't help. A simpler way of introducing C program language to such lads is what goes ahead! That brings us to the very first question:

What is C?

C is definitely a programming language. Now there exists different types of languages based on their procedure of execution. C falls under Object Oriented Programming or Procedural Programming Language.


Talking about its origin, one will have to give formal credits to one man: Dennis Ritchie, who between 1969-73 gave shape to initial model of C language.

Dennis Ritchie (1941-2011)
Dennis Ritchie (1941-2011)

The sole purpose of developing this language back then was to assist in writing complex codes for an entire operating system. With some basic features like, minimal style, low-level access to system memory, distinguished codes C was used to develop operating system.

Other languages, in fact, directly or indirectly borrowed some slices from C and were evolved to work with some advanced features.

In your higher secondary education you've probably read about C++, which is a superset of C language.

How to Begin C Program?

Once you've known about the introductory segment of C, we now step further into coding a C Program. Well, throwing a block of code straight up will not be wise, so let's break and learn.

1. Structure of C program

For writing a successful code, there is a proper format to follow, that is the structure of a C Program. Take a look at the following code segment:

#include<stdio.h>  /*a header file*/
main()             /*the main function*/
{
 int a=1;          /*declaring data type*/
 printf("%d",a);   /*output statement*/
 return 0;         /*return statement*/
}

Breaking the code into few fundamental parts, here's what we get:

a. Header Files: Any C program is incomplete without calling the header files. You can easily identify a header file as it ends with extension ".h". There are several header files like, stdio.h, conio.h, math.h, etc.
Syntax: #include<headerfilename.h>

b. Main Function Calling: Once the header files are being called, we have to start by calling the main() function. We use the following syntax for that purpose:
Syntax: void main()
        {}


c. Variable Declaration: Next, a variable is declared in memory by applying following syntax. Remember, without declaration no variables can be used.
Syntax: int a=1;


d. Body: Contains set of statements to direct the programming stuff. All sort of actions are carried out in this portion.

e. Return Statement: Lastly, a return statement. The return statement refers to the returning of the values from a function.
Syntax: return 0;

2. Writing the first code:

Below, is the first C Program code:

#include<stdio.h> 
void main() 
{ 
    printf("Hey there!"); 
    return 0; 
}

Let's look at different components of this code one by one.

Line 1: The header file stdio.h is called. Notice the # symbol at the beginning. This is the pre-processor directive. Unless we call that stdio.h file, we can't use the printf () function ahead in the program. Because, the function is defined in that header file.

Line 2: Any program must contain a section that contains set of statements or instructions to be executed while compiling. Such set of statements are added within the main() function. The main() fiction can have several data types to specify the type of data the program after execution will return. We'll cover that on another post.


Line 3&6: The pair of braces { } define a scope and mainly used in functions and control statements like if, else, loops. All types of function must bear these braces.

Line 4: The command printf() is a standard library function that lets us print something on standard output. The ; at the end of printf indicates termination of a statement.

Line 5: The return statement returns the value from main() function. The value 0 usually means successful termination.

3. Compiling C Program:

C Programs can be compiled on multiple platforms starting from Windows, to Android. There are even few online compilers:


which lets you finish the job without even installing any compilers on your device.

Windows: Dev-CPP as well as CodeBlocks are awesome C compilers. But, for ANSI C the DosBox comes into play.

Linux: For Linux, although gcc comes bundled with linux, you can try installing CodeBlocks with Linux.

I hope you have enjoyed watching this introduction to c language. Before leaving comment below, if you've still written your first program in C? I'll see y'all soon.