×

Hello World In C


In this chapter, We will write our first c program.


Now that our system is ready to compile and run C programs, Let's dive in to write our first Computer program.

Now in order to compile our first C program, we need to write a program, to do so follow the instructions below.

First, open a text editor like gedit by typing this command:

gedit

or you can just search in your programs and open gedit, now if you don't like gedit, its fine choose your favorite text editor.

Second, write down below code or just copy and paste it in the text editor.

File: hello.c
#include<stdio.h>
void main()
{
    /* This will print "Hello, World! Welcome to Earth Coding" without quotes on the screen */

    printf("Hello,World! Welcome to Earth Coding");

}

Third, Save the file as hello.c.

Fourth, Now open a terminal and navigate to the path where you have saved hello.c

$cd /path/to/hello.c

To be able to run this small code, we need to compile.

Fifth, Lets compile the code.

gcc hello.c

This will compile the program and create executable machine code in the file named a.out.

Six, Now to see the output, we need to execute this a.out. To do so just copy and paste the below command in terminal.

./a.out

This will print the following output on the terminal console.

Output
  Hello,World! Welcome to Earth Coding 

Congratulations⚆⚆⚆⚆⛳ You have created and executed your first computer program in C programming language.


In the next chapter i.e. program structure, We will study basic building blocks of a c program and understand what each statement in the above code means C.

Sharing is caring: