Introduction to C Programming Language

Introduction to C Programming Language


What is Programming?

Computer doesn't know our language directly. Computer programming is a medium for us to communicate with computers. Just like we use bengali or english to communicate with each other, programming is a way for us to deliver our instructions too the computer.

In short the medium through which computer can understand us is called programming language.

What is C Language?

C is a general-purpose programming language that is extremely popular, simple, and flexible to use.It was developed by DENNIS RITCHIE in 1972. It was mainly developed as a system programming language to write the UNIX Operating System. It is a structured programming language that is machine-independent and extensively used to write various applications, Operating Systems like Windows, and many other complex programs. 

History of C :

~The base of programming languages is 'ALGOL' and It was first introduced in 1960. It introduced the concept of structured programming to the developer community. 

~In 1967, a new computer programming language was announced called as 'BCPL' which stands for Basic Combined Programming Language. BCPL was designed and developed by Martin Richards, specially for writing system software. This was the era of programming languages. 

~Just after three years, in 1970 a new programming language called 'B' was introduced by Ken Thompson that contained multiple features of 'BCPL.' This programming language was created using UNIX operating system at AT&T and Bell Laboratories. Both the 'BCPL' and 'B' were system programming languages.

~In 1972, a great computer scientist Dennis Ritchie created a new programming language called 'C' at the Bell Laboratories. It was created by using the concept of 'ALGOL', 'BCPL' and 'B' all of the programming languages. 'C' programming language contains all the features of these languages and many more additional concepts that make it unique from other languages. 

    Initially, C language was developed to be used in UNIX operating system. It inherits many features of previous languages such as B and BCPL. To assure that 'C' language will remain standard, American National Standards Institute (ANSI) defined a commercial standard for 'C' language in 1989. Later, it was approved by the International Standards Organization (ISO) in 1990. 'C' programming language is also called as 'ANSI C'.

 Why Should We Learn C?


1. Possibly why C seems so popular is because it is reliable, simple and easy to use. this programming language is a must for students and working professionals to become a great Software Engineer specially when they are working in Software Development Domain. 
2. Major parts of popular operating systems like Windows, UNIX, Linux is still written in C. This is because even today when it comes to performance (speed of execution) nothing beats C.
3. Nobody can learn C++ or Java directly. This is because while learning these languages you have things like classes, objects, inheritance, etc. Hence one should first learn all the language elements very thoroughly using C language before migrating to C++, C# or Java.

So if you know 'C', you can easily grasp the knowledge of the other programming languages that uses the concept of 'C'.

Some of C's most important features include:

1. Fixed number of keywords, including a set of control primitives, such as if, for, while, switch and do while.
2. Multiple logical and mathematical operators, including bit manipulators.
3. Function return values are not always required and may be ignored if unneeded.
4. FIles are separately compiled and linked.
5. Control of function and object visibility to other files via extern and static attributes.
6. Typing is static.

Let's start with C programming :


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

 Structure of C program :

After the above discussion, we can formally assess the structure of a C program. By structure, it is meant that any program can be written in this structure only. Writing a C program in any other structure will hence lead to a Compilation Error.

The components of the above structure are :


Header Files Inclusion : 

The first and foremost component is the inclusion of the Header files in a C program. A header file is a file with extension '.h' which contains C function declarations and macrodefinitions to be shared between several source files. In the upper program there the <stdio.h> is the Standard Input Output header file.

Some of C Header files: 

1. stddef.h : Defines several useful types and macros.
2. stdint.h : Defines exact width integer types.
3. stdio.h : Defines core input and output functions.
4. stdlib.h : Defines numeric conversion functions, pseudo-random network generator, memory
5. allocation string.h : Defines string handling functions.
6. math.h : Defines common mathematical functions .


Syntax to include a header file in C :  #include  


Main Method Declaration : 

The next part of a program is to declare the main() function. 

The syntax to declare the main function is :  int main() 


Variable Declaration: 

The next part of any C program is the variable declaration. It refers to the variables that are to be used in the function. Please note that in the C program, no variable can be used without being declared. Also in a C program, the variables are to be declared before any operation in the function.

Related Program : 

//C program to print an user defined data of a integer variable

#include<stdio.h> 
int main()
{
  int a; 
  printf("Enter an integer : ");
  scanf("%d", &a); 
  printf("The integer is : %d\n", a); 
  return 0;
}
Output :



Body: 

 Body of a function in C program, refers to the operations that are performed in the functions. It can be anything like manipulations, searching, sorting, printing, normal printing etc.

Return Statement: 

The last part in any C program is the return statement. The return statement refers to the returning of the values from a function. This return statement and return value depends upon the return type of the function. For example, if the return type is void, then there will be no return statement. In any other case, there will be a return statement and the return value will be of the type of the specified return type.
        In the upper C program the return 0; is the return statement as we took int return type.