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.

About    Contact    Sitemap    Terms    Privacy