Join us Now |  Forgot Password? | Forgot UserName?


Learn step by step

C-Program Structure

Before we start the study of basic building blocks of C language, let’s see a minimum C program structure so that we can take it as a reference in our upcoming chapters.

C Hello TutOn Example

Various parts that a C language basically consists of are:

  • Variables
  • Functions
  • Statements and Expressions
  • Preprocessor Commands
  • Comments

Let us look at a simple code below that would print "Hello TutOn".

#include <stdio.h>
int main()
/* my first program in C */
printf("Hello, TutOn! \n");
return 0;

Various parts of the above program:

1. The first line of the program #include is a pre-processor command, which tells a C compiler to include a header file (i.e. stdio.h) before going to actual compilation.

2. The next line int main() is the main function where program execution begins.

3. The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments about the program.

4. The next line printf(...) is another function available in C which causes the message "Hello, TutOn!" to be displayed on the screen.

5. The next line return 0; terminates main()function and returns the value 0.

Compile and Execute C program:

The most important thing to which we are going to look at it is how to save the source code in C , save and compile the code.

Below here are the following steps:

1.Give the extension as Hello.C and save it.

2.Open a command prompt and go to the directory where you saved the file.

3.Type gcc hello.c and press enter to compile the code.

4.We will get to next line by command prompt and a.out executable file will be generated if there will be no errors in the code.

5.To execute the program type a.out

6.“Hello TutOn” will be printed on the screen and will be visible to us.

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

Related Videos