Getting started with programming in C

Before you start programming in C , you need to have a compiler which compiles and executes our programs.
In this tutorial you will learn how to find compiler and how to start writing a C program.

Step 1) Finding a suitable Compiler to start programming in C:

There are certain online compilers such as http://ideone.com/ or http://codepad.org/ that can be used to start C without installing a compiler on your Personal Computer.Otherwise you have to install compiler on your personal computer. Some compilers for Windows and linux operating system are listed below:
Compiler for windows Operating System:
There are many compilers available for windows based platform at free of cost , compilers used to compile C programs are Dev-CPP and Code Blocks etc.
Compiler for Linux Operating System:
For Linux platform, there is an inbuilt compiler named as GCC ,you can use Code Blocks with Linux based platform.
I will highly recommended you to use Code block as it is as it works on various operating systems and supports a rich set of programming languages like C,C++(which is super set of C language),java etc.


Step 2) Example of basic program in C language:

Line 1:     #include <stdio.h>

Line 2:       int main(void)

Line 3:          {

Line 4:             printf("HelloWorld");

Line 5:             return 0;

Line 6:          }

Output:

HelloWorld


Let us analyse the code of program line by line :

Line 1: [#include <stdio.h>]
Lines that starting with # indicates a pre-processor.
In above example, pre-processor copies the pre-processed code of library file stdio.h to the current file.
The ‘.h’ files are called header files in these header files generally contain declaration of functions like header file stdio.h contains declaration of function printf() which is used in the program.

Line 2 [ int main(void) ]
In C, the execution begins with first line of main() I.e. this line is starting point for execution of any program by compiler used to compile a C program like dev-CPP for windows operating systems or gcc for Linux operating systems based personal computers.
The void written in brackets (“()”) indicates that the main function doesn’t take any parameters.
The int written before main function indicates the return type of main() function i.e. written type of main() function is an integral value starting from 0 to 9.

Line 3 and 6: [{and}]
In C programming language, a pair of curly brackets defines the scope of the variables/parameters and it is mainly used in functions and control statements like if, else, loops.
All functions must start and end with curly brackets.

Line 4 : [ printf(“HelloWorld”); ]
printf() is a standard library function written in header file “stdio.h”. It is used to print something on standard output i.e. use to print data on display(console screen).
The semicolon(‘;’) at the end of printf function indicates line termination.
As per the syntax of C programming, semicolon is should be always used to indicate the end of statement.

Line 5 [ return 0; ]
This return statement returns the value to main() function .
The value returned by the function may be used by operating system to know the termination status of your program.
The value ‘0’ typically represents success.