Hello world..!

“Hello, world!” is the program that is cosidered as first program of exection in every lanagauage.Every programmer started his development through that simple hello code.

Let’s begin by writing our first C program that prints the message “Hello, world!” on the display console:

Hello, world!

Step 1: Write the Source Code: Enter the following source codes using a programming text editor (such as NotePad++ for Windows or gEdit for UNIX/Linux/Mac) or an Interactive Development Environment (IDE) (such as CodeBlocks, Eclipse, NetBeans or MS Visual Studio – Read the respective “How-To” article on how to install and get started with these IDEs).

Do not enter the line numbers (on the left panel), which were added to help in the explanation. Save the source file as “Hello.c“. A C source file should be saved with a file extension of “.c“. You should choose a filename which reflects the purpose of the program.

1
2
3
4
5
6
7
8
9
/*
 * First C program that says Hello (Hello.c)
 */
#include <stdio.h>  // Needed to perform IO operations
 
int main() {                    // Program entry point
    printf("Hello, world!\n");  // Says Hello
    return 0;                   // Terminate main()
}                               // End of main()

Step 2: Build the Executable Code: Compile and Link (aka Build) the source code “Hello.c” into executable code (“Hello.exe” in Windows or “Hello” in UNIX/Linux/Mac).

  • On IDE (such as CodeBlocks), push the “Build” button.
  • On Text editor with the GNU GCC compiler, start a CMD Shell (Windows) or Terminal (Mac, Linux) and issue these commands:
    // Windows (CMD shell) - Build "Hello.c" into "Hello.exe"
    > gcc -o Hello.exe Hello.c
     
    // UNIX/Linux/Mac (Bash shell) - Build "Hello.c" into "Hello"
    $ gcc -o Hello Hello.c

    where gcc is the name of GCC C compiler; -o option specifies the output filename (“Hello.exe” for Windows or “Hello” for UNIX/Linux/Mac); “Hello.c” is the input source file.

Step 3: Run the Executable Code: Execute (Run) the program.

  • On IDE (such as CodeBlocks), push the “Run” button.
  • On Text Editor with GNU GCC compiler, issue these command from CMD Shell (Windows) or Terminal (UNIX/Linux/Mac):
    // Windows (CMD shell) - Run "Hello.exe" (.exe is optional)
    > Hello
    Hello, world!
     
    // UNIX/Linux/Mac (Bash shell) - Run "Hello" (./ denotes the current directory)
    $ ./Hello
    Hello, world!

Add a Comment

Your email address will not be published. Required fields are marked *