C - hello world

How to run a Hello World script in C using GCC

This short tutorial is a guide to help familiarize you with writing a simple Hello World program using C, the GCC compiler, and Pico (a text editor). It uses a Linux VM.

1) With Ubuntu running on your virtual machine, open the Terminal window.

2) Create a file using Pico by entering the command ‘pico gcctest.c’

3) To create a helloworld script simply type the following:

#include <stdio.h>

main()

{

printf(“Hello World!\n”);

}

  • Then save the file by pressing CTRL+O

  • Leave the file name as is, and then hit Enter.

  • Exit the file window by pressing CTRL+X.

This is what it should look like:

4) Now that your helloworld script is created, you must first compile the script.

  • Entering the command

gcc gcctest.c

  • If no error messages are returned then you have successfully compiled your script.

5) Run the script you created

  • type the command

./a.out

  • Your “Hello World!” message should be returned on the following line.

6) This is what you should see:

6) Congratulations, you have successfully created and ran a helloworld script using gcc!

For Additional help you may wish to refer to the links below: