First Program Hello World in C

The most basic and compulsory thing for a beginner programmer is to learn syntax of programming language. That's why we start to teach beginners a kind of standard first program which is known as "Hello World". Basically purpose of this program is to teach and learn how to create, open and run the file of programming language and how to display or print-out text on console screen.


First Program Hello World in C


Let's dive into topic's discussion to understand it in detail.


Explanation:

We will understand all the details of our topic "First Program Hello World in C".

Creating File:

The most important and basic thing in any programming language is to create New File. For this purpose follow below steps:

  • First of all, open your any installed IDE of C where IDE stands for integrated development environment which has Code Editor and Compiler or Interpreter of specific language. I will use Dev C++ which is an IDE for both C and C++ which means you can write and run these languages files on it.
  • Then click on New File button on Top Left corner of Dev C++, due to which a new Untitled File will be open.

Basic Code:

After it, first we will enter Basic Code which is compulsory before writing our own  main code. For that basic code, we will write followings:

  • First import built-in library / header file stdio.h which we needed for basic code which is used to print out and user-input anything. Remember you can import any built-in and custom libraries / header files.

    #include <stdio.h>
    

  • Then we will write main() function with empty body except a one command at end curly bracket which is return 0;

    int main() 
    {
       // Write your main code here
       
       
       return 0;
    }
    

Main Code:

Now after basic code we can write Main Code. In our case we want to print our text "Hello World". For it we will call built-in function printf() which is present in our built-in library stdio.h This function has no any actual parameters but just enter two quotation marks " " and between these two marks we write our text which we want to display on console and then enter semicolon ; after ending small bracket.

printf("Hello World !");

Source Code & Output:

The source code and output of our topic is given below so that you can easily practice and understand it by running code on your computer and verify its output.

Source Code:

The source code of "First Program Hello World in C" is below.

#include <stdio.h>

int main() 
{
   // printf() built-in function to displays the string/text
   printf("Hello World !");
   
   
   return 0;
}

Output:

The output of "First Program Hello World in C" is below.

Hello World !

Dry Run With Example:

We can print any our desired text on console in same way as in above source code we printed Hello World. You can also print anything by entering in printf() function for example:

printf("Today I took my 1st lesson of C Programming on Search 2 Programming by M Usman.");

Then the built-in function printf() will display the text "Today I took my 1st lesson on C Programming." your on console screen.

Tags

Post a Comment

0Comments
Post a Comment (0)