Module 3    C - Program Structure

Before we study the basic building blocks of the C programming language, let us look at a bare minimum C program structure so that we can take it as a reference in the upcoming chapters.

Hello World Example

A C program basically consists of the following parts −

Let us look at a simple code that would print the words "Hello World" −

Live Demo
#include <stdio.h>

int main() {
   /* my first program in C */
   printf("Hello, World! \n");
   
   return 0;
}

Let us take a look at the various parts of the above program −

Compile and Execute C Program

Let us see how to save the source code in a file, and how to compile and run it. Following are the simple steps −

$ gcc hello.c
$ ./a.out
Hello, World!

Make sure the gcc compiler is in your path and that you are running it in the directory containing the source file hello.c.