Your First C Program

In previous two sections we have learnt how to setup c environment and steps in c program compilation. Now we are going to learn how to write a simple C program.

Type the following program into your favorite editor

//C simple program 

int main()
  /* It prints Hello World */
  printf( "Hello, World\n");
  return 0;

Save it as hello.c, Compile and execute using following steps

gcc hello.c 
Hello, World

Let us look at various parts of above c program

  1. The first line of program  //C simple program  is a single line comment. This line is ignored by compiler. 
  2.  The Next line of the program #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation. its called as header file.
  3. The next line int main() is the main function where program execution begins and  int is the return type of main function.
  4. The next /*It prints Hello World */ is a multi line comment.
  5. The next line printf(...) is another function available in C library which causes the message "Hello, World" to be displayed on the screen.
  6. The next line return 0; terminates main()function and returns the value 0.
Banner to

Hide Page Information

Your First C Program, C program structure

Your First C Program, C program structure

how to write first C Program, C program basic structure, hello word c program explanation