Sunday, June 02, 2013

C Tutorial : Introduction to C language

Leave a Comment Follow us on twitter
In this C tutorial we are going to focus over the introductory part of C language. C is a very popular programming language developed by Dennis Ritchie in 1972. C is not an Object Oriented Programming language as C++ is but it is a structured language. Structured languages are easier and allow the variety of programs in small modules. So, C programs are easier to develop as compared to C++.

As C Program is high level language, so we need to convert this high level language into machine language. For this purpose there are various online C compiler and interpreter available in the market but the popular one is turbo c. These compiler and interpreter convert the high level language or assembly language into machine language (i.e. in binary form 0 and 1).


Let's see the Structure of C Program along with an example.

 
Header file section
Global variable declaration section
Main() Function (along with return type)
{
Executable statements
}
User-defined Functions
{ }


E.g.  :
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("\nEnter the value of a and b:");
scanf("%d%d",&a,&b);
printf("Sum of a and b is :%d",a+b);
getch();
}

=> Header file Section: This is the mandatory section. In the above program we have used two header files "stdio.h" and "conio.h". "#" is pre-processor directory and "include" is used to include stdio.h in the program. "stdio.h" means Standard Input Output and "conio.h" means Console Input Output. File comes under "stdio.h" in this program are printf and scanf while getch comes under "conio.h.".

=> Global variable declaration section: Global variable means those variables that can be used in more than one function. They are declared before the main() function.

=> Main() function : In the above program, void main() is used. All the necessary part of the program is written under main() function. You can also write int main(), float main(), double main() etc.

=> Executable statements: These are those statements that actually do some computation like a+b; etc.

=> User-defined functions: Functions are very popular in C language. To divide the big program into small modules we can use functions. It is quite helpful in recursion programs.

=> Comments: Comments are not the mandatory part of a c program but if you write comments it will help to understand the logic as well as the definition of the program. // is used to write a single line comment while /* */ is used to write multiple line comment.


E.g.:
// This is a single line comment.
/* This
is a multiple
line comment */

In this C Tutorial we discussed about introduction to C language. Hoping that you are now able to understand C and learning C is a better experience, we will see further C tutorials in later posts.

0 comments:

Post a Comment