How to Create Hello World in C

by Zacharia Alaoui in Teachers > University+

294 Views, 2 Favorites, 0 Comments

How to Create Hello World in C

CPic.JPG

I am making a program that prints out "Hello World" in the C language. I am going to teach new upcoming programmers how to write their first program in C.

Supplies

terminalPic.png
  • It is suggested that you have already downloaded Visual Studio Code to your computer or another IDE that allows you to run your code, I am going to give instructions on how to create your first program on Visual Studio Code. Here is the link if you would like to download Visual Studio Code, https://code.visualstudio.com/download.


  • If you do not have IDE installed, I would recommend you use an online free IDE called Replit. If you would like to use the online IDE, the link to it is https://replit.com/.


  • I am going to provide the procedure on how to output “Hello World!” in your terminal window. The terminal window is where you are going to see your output.

Create the File

clickOnfile.png
  •  If you are using Visual Studio Code the first thing you need to do is create a file. The way to do this is to click file on the top left and press new file and type in a name for your file, make sure to use .c after the name of your file.


  • If you are using Replit, Once you are on the website you should click create Replit, then you should select the C template. After you have selected the template, you must make a title, I recommend you make your title Hello.c.

Include the Library

  • The 2nd step in this procedure is to include the library that allows you to take in input and be able to output. To include the library use #include<stdio.h> on the first line of your program

Create Main Method

  • The 3rd step is to create your main method, the main method is where your program executes your program. It is important that you include it. The way to include the main method function is like, int main() {}.

Create Print Function

printFuntion.png
  • The 4th step is to use the print function inside the braces of the main method function. The print function in c programming is called printf(). The picture below shows a visual of how it should look.
  • Inside the parentheses, you need double quotes like printf(“”). This allows you to print out strings. Strings allow you to store characters and text, for example, the word “Hello” is considered a string. And the letter ‘A’ is a character in C programming.
  •  Strings are an array of characters and it has a NULL terminator at the end. An array of characters means that there is a sequence of characters.
  • A NULL terminator tells the computer that it has reached the end of the string. A NULL terminator looks like '\0', every string has a NULL terminator. For example, the word “Hello” would have a NULL terminator at the end like “Hello\0”. This tells the computer that it has reached the end of the string/word.
  • You do not need to worry about including the NULL terminator the computer does it for you.

Write Out Hello World!

  • The fifth step is to write “Hello World!” inside the double quotes. After you put the string inside the double quotes make sure to put a semi-colon at the end of the last parentheses. For example you would do printf(“Hello World!”); .
  • If you would like to have a new line after you print Hello World!. You would also need to have the new line character right after the exclamation point. For Example it would look like printf(“Hello World!\n”);. This tells the program to have a new line after you print Hello World!.

Final Step Run the Code

Hello.c output.JPG
  • The final step would be to run your code by pressing the play button on the top right of your screen, then click run code. Then you should see "Hello World!" Printed in your terminal window followed by a new line. 
  • The picture below shows how the program should look, and how the output should look like.