The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as
well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct. Donald E. Knuth

Basic Syntax

C Program Structure
Let's look at the most basic C program :

 * File : main.c
 * Author : csegeek
 * Description : My first C Program
#include <stdio.h>

/* program execution starts at main() */
int main() {
   printf("Hello World!"); /* prints "Hello World" */
   return 0;

When the program is run, it prints the following output :
Hello World!

Comments are a way of explaining what your program does. They are enclosed within /*      */ and are not considered for compilation and execution. Comments are ignored by the compiler and are just a means for you and others to understand the piece of code.

< stdio.h > Header File
#include is a preprocessor directive which tells preprocessor to include the contents of stdio.h header file before compilation. stdio.h contains code that tells compiler what printf ( ) function will do and ofcourse it contains code for other standard library functions. There are many other header files which we should be included as and when required. Every header file consists of a set of functions which we can use to perform different tasks.

main ( )
The program execution begins at the main ( ) function. int (integer) specifies the return type of main ( ) funtion. Every program must have one and only one main ( ) function.

printf ( ) function
printf causes the message " Hello World " to be printed on the screen. printf ( ) is a standard library function. You will learn about other functions as you move along.

Return Type of main ( )
main ( ) returns an integer type value. The statement return 0; causes termination of the main ( ) function or the program and returns 0 ( integer ) to the Operating System.

We have described the building blocks of a very basic C program. Please go ahead with the tutorial to understand the terminologies described here better.

Back | Next