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.



3 comments:

  1. Nice I am also creating a blog on basic C++....
    http://beginners-programmingtutorials.blogspot.com/

    ReplyDelete
  2. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete
  3. Nice and very helpful article keep posting helpful programming examples
    I have writes my first C program in 1st year of my college

    ReplyDelete