1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

First C Program Hello World

Discussion in 'C' started by lionaneesh, Jun 10, 2011.

  1. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    In this tutorial we’ll be making our first running C Program, It will simply print out a Message on the Screen! So let the coding begin. :party:
    hello.c
    Code:
    #include<stdio.h>
    
    int main()
    {
        printf("Hello World! This is my first C Program ");
        return(0);
    }
    
    Note: I am using GCC compiler on a UNIX to compile my C programs, for different compilers please see your Compiler manual!

    Compiling:-
    Code:
      gcc hello.c –o hello  
    
    Explanation:-
    1. The first of the program simply includes the header file stdio.h (Standard IO) this file is necessary as it contains Constants, definitions etc, for the common functions like printf() etc . That’s why you’ll find it in almost every C program.
    2. The second line “int main()” , this tells the compiler to declare a main() function and it will return an int [int = Integer] after its execution.
    3. In the third line we declare a printf statement, printf stands for print format string , This functions simply prints a format string to the screen , in this case it prints “Hello World! This is my first C Program” on the screen.
    4. The fourth line includes a return statement this simply returns a status code. This status code simply means if the program was successfully executed or a error was occurred.
    Now let’s compile our program and see the output. To run the program simple ‘cd’ to the path where the program is situated and enters its name at the command prompt.

    Output:-
    Code:
    Hello World! This is my first C Program 
    
    Voila, Congratulations we just executed our first program!

    That’s all for this article, Stay tuned for more.
     
  2. jam143

    jam143 New Member

    Joined:
    Jul 1, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    n/a
    Location:
    philippines
    where did you get your compiler?
     
  3. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    I am using GCC on Unix which is mostly available on almost all Unix Machines

    For further Info Check :-

    http://gcc.gnu.org/
     
  4. Delois

    Delois New Member

    Joined:
    Aug 6, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    yeah I remember this program at first day of my c class where I was suppose to create program which prints this "hellow word" 10 times with help of for loop.
     
  5. Sarwat

    Sarwat New Member

    Joined:
    Nov 5, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Lecturer
    Location:
    Karachi-Pakistan

Share This Page