Introduction to C Programming Language

C is a programming language developed by AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. C is reliable, simple and easy to use. C has survived for more than 3 decades. C language is a base to learn different programming language.

If you want to learn C++ or JAVA, without the knowledge of C it becomes very difficult to learn these programming languages. Many major components of popular operating systems like Windows, UNIX, LINUX is still written in C.

Nothing beats C in terms of speed of execution.

Before starting with the programming, let’s have a look at the C Character set.

Any alphabet, digit or special symbol can be termed as a character. Below table shows list of valid alphabets, digits and symbols allowed in C.


Digits :

Special Symbols :

Following are the basic data types:

  1. Numeric data type: deals with numeric data such as integer or float data type
  2. Non-numeric data type: deals with non numeric data such as characters
  3. Integer data type: deals with integer or whole number
  4. Real data type: deals with numeric data that includes fractions
  5. Enumerated data type: These data types are defined by the user

Constants, Variables and Keywords in C

A constant, Variable or a keyword in C language can be formed from any combination of Alphabets, Digits and Special Symbols. A constant is an entity whose value does not change throughout the program execution.

A variable is an entity whose value keeps on changing throughout the program execution. However, it’s not a rule that the value of the variable will change. A variable value might remain same throughout the program execution. However the main difference between variable and constant is that we can’t change the value of constant in between the program, but we can change the value of the variable during program execution.

Let us take an example:
We define a variable named x in a program. Let us say x=3.
After some time during execution we change the value of x to 6. Now, x=6.
Here value of x is getting changed. But the value of 3 and 6 will never change. Hence, x is called a variable and 3 is called a constant.

Keywords are the words whose meaning has already been explained to the C compiler. The keyword cannot be used as the variable name. If we try to do so we are trying to assign new meaning to the keyword. The keywords are also known as ‘Reserved words’.

E.g.: for, if, static, while, do, break etc.

Understanding the program in C

Let us learn the above program in detail.
Line 1 thru 4:
This is the comments in the program. It is called multiline comment. The text written within /*…*/ are ignored by the compiler.

Line 5:
This is another way to comment a text or statement. It is called single line comment. The entire line following the tag // is ignored by the compiler.

Line 6 and 7:
#include is known as pre- processor directives. It tell the compiler to include text from another file, stuffing it right into your source code.
is a file name enclosed within angle brackets. The whole statement #include tells the compiler to take text from the file stdio.h and stick it into your source code before the source code is compiled.

Line 8:
This is the start of the main function. The program execution starts from this function. main() is the name given to a set of statements. This name has to be main(). The statement that belongs to main() are enclosed within a pair of braces {}.

Line 10:
Any variable that we need to use must be declared before using it.

Line 12 thru 15:
Here the values are getting assigned to the variables.

Line 16:
Once the value of a+b is assigned to c, it needs to be displayed on the screen. We can use readymade library function to display the value on the screen. One such function is printf().

The general form of the printf() function is:
printf("", );

can contain,
%d for printing integer values
%f for printing real values
%c for printing character values
\n is a newline character. It takes the cursor to the new line. It is one of the several escape sequences available in C.

Line 9 and 17:
The function body should be enclosed in opening and closing braces.

Though comments are not necessary, it is a good programming practice to include comments in the program. Adding comments in the program increases the readability of the program. We can include as many comments as possible. A comment can be split over more than one line as shown in the above program (Line 1 thru 4). Any C statement always ends with a ;

Receiving Input
In the above program, we have assigned the value 5 and 4 to a and b respectively. But, every time we cant do so. A situation might arise wherein we need to take input from the user. Here we will learn how to receive input from the user.

scanf() – It is a standard library function in C. This function will accept the input from the user and stores it in a particular user defined variable.

The syntax of this function is:
scanf( “”, &);

can contain,
%d for printing integer values
%f for printing real values
%c for printing character values

‘&’ before the variable name is a must. ‘&’ is the ‘address of’ operator. It gives the address used by the variable in memory.

Let us consider an example:

When we execute this statement, it will ask for input. Suppose the input given is 5. 5 will be stored as integer at the address of variable a. we can print the value stored at that address using simple printf() statement as shown below.
printf(“%d”, a);