This blog is under construction

Saturday, 3 March 2012

My First C Program

Program is a set of instructions which can be executed in a specific sequence to get the desired output.

Below is the simple c program(hello.c) that prints "hello world" on the output screen.

     #include <stdio.h>     /* Header file */
     main() {                     /* Program execution starts here */
          printf("Hello world");  /* Built-in function - printf() */
          return 0;

  • Comments should be enclosed within /* */ and they won’t get executed.
  • Program execution always start from the main function.
  • printf() is a library function available in “stdio.h” header file.  It is used to format and print data.
  • Header file contains the built-in functions and pre-defined variables.

hello.c is the file containing the above program.  Below command is used to compile the c program.

gcc <C File Name> 
gcc hello.c

As the result of compilation, we will get an executable named a.out in the same directory. Running the executable "a.out" would print the program result on the output screen.

1 comment:

  1. Nice I am also creating a blog on basic C++....