Vlad Budnitski

Getting started

Have you ever wondered:

These are the common questions asked by beginner C programming students. In this blog post tutorial, we will cover the basics of writing the first C Hello World program, with step-by-step instructions.

Prerequisites: 

This tutorial requires no prior knowledge of programming. You will learn how to write your first lines of code from scratch.

With the help of any text editor, you should be able to create a C program and specify the instructions in the C language. Then, thanks to a translator guy (a.k.a. “the compiler”), you should be able to translate it to the machine language. This is a language that the computer will understand and be able to execute.

Person in front of laptop and desktop displaying code

Displaying “Hello World” in C

Once you know what a programming language is, then instead of telling the computer in English: 

// Display a "Hello World" message on the screen!

We will create a “hello_world.c” file in a text editor and specify the commands using the C language in the following way:

#include <stdio.h>
int main() {
   printf("Hello World!");
   return 0;
}

This would be your first program to print “Hello World!” in C (using the C language rules, syntax, and structure).

C Programming Bootcamp – The Complete C Language Course

Last Updated November 2022

Bestseller
  • 395 lectures
  • All Levels
4.4 (4,896)

C Programming 2022: Master the Fundamentals of C Programming Language. Join the Comprehensive C Bootcamp Masterclass! | By Vlad Budnitski

Explore Course

Exploring the C Hello World program

Now let’s break this program into smaller pieces and explain them in detail:

Including libraries and files

#include <stdio.h>

If you want your program to display messages on the screen, you need to include appropriate functionalities for that. That’s why the “#include” preprocessor in C is being used. 


In this line, we include a file called “stdio.h”. It’s a library of “stdio” (standard input/output) pre-written code functionalities. It allows the program to use various input and output commands in the program. We are going to use one of its methods to display/print a “Hello World” message to the screen.

The main function

int main()

The main function is considered to be a part of every C Program. It also can be represented in various forms (based on the tutorials you learn from). For example:

This function is also seen as the “entry point” to the program. That’s where the execution of every C program starts.

Curly brackets

{}

The curly brackets specify the actual boundaries of the main program. The opening braces ‘{‘ show the beginning of the commands block. The closing braces ‘}’ show the end of it. The code you want to execute is going to be between the curly brackets.

Printf

printf("Hello World!");

One of the common commands you’re going to work with is the printf function. That’s a “printing/displaying to screen” function we can use thanks to the methods that were “included” from the “stdio.h”. The printf function gets the text between the “quotation marks” and displays it on the screen.

Return

return 0;

Used to indicate an “exit status” (successful) of the program. A status 0 usually indicates a successful execution and termination of the program.

The Results

Taking all these parts together will get you a “hello_world.c” file:

#include <stdio.h>
int main() {
   printf("Hello World!");
   return 0;
}

Top courses in C (programming language)

C Programming For Beginners – Master the C Language
Tim Buchalka’s Learn Programming Academy, Jason Fedin
4.4 (28,091)
Bestseller
Advanced C Programming Course
Tim Buchalka’s Learn Programming Academy, Jason Fedin
4.4 (2,933)
The Complete C Programming Bootcamp
Byte Garage, Byte Garage Instructors
4.4 (943)
Learn C++ Programming by Making Games
Serge Lansiquot
4.6 (488)
Linked Lists with C
Portfolio Courses
4.8 (39)
Highest Rated

More C (programming language) Courses

More Notes

  1. Semicolon (;): Most of the commands you’ll use will end up with a semicolon at the “end” to specify the end of a certain command.
  2. Indentation: The indentation of the code is being added to make the code more readable. Although in this program it doesn’t look like much of a help, it will play a major role in the future complex programs.
  3. Compiler: It’s considered to be the “translator” program. It translates the source code (C language, in our example) into a target code (machine language, for example).
  4. Text Editor: That’s where you actually create and write your “source code” (.c file) — in C language. And the compiler should transform the “source code” into “target machine code.”

Congratulations!! You have created your first program in C! That’s the actual “code” with C syntax for a C Hello World program! Hooray!

How to run your first C Hello World program?

So you’ve created your first amazing program in C Language. Now what? You need to run it!

The program is written in C, and you already know the computer only works with its own language. To run the program you will need to translate it from C Language to Machine Language. Once the compilation process is done, you should be ready to run it and observe the expected results.

What do we need to download and install?

We need to compile the program that we have created. For that, we may install a compiler as standalone software or download and install an IDE, or Integrated Development Environment. This is a highly integrated environment that lets you develop your programs more easily. It includes a text editor, compilers, linkers, plugins, debuggers, and more. Everything you need to write C code in one place.

So here’s a list of my top 3 recommendations for IDEs to get started with C:

  1. Code::Blocks: Code::Blocks is a good practice for beginners since it’s light, extensible, and a configurable IDE. Code::Blocks is also a Cross Platform, meaning it’s supported on Windows, Linux, and Mac. You can download it from their site. If you’re using Windows, make sure you download the “mingw-setup” (with a Compiler and a Debugger).
  2. Visual Studio: Visual Studio is a very functional IDE from Microsoft. It’s packed with lots of features, such as code browsing, colorization, and navigation. It also includes autocompletion of symbols, a built-in compiler, and a build system. On top of that, it provides a line debugger, a built-in testing, and code analysis tools. You can download Visual Studio from Microsoft’s official website.
  3. Visual Studio Code: Although not an IDE, VSCode is a good option to start with. It’s a Cross Platform, light and extensible editor, and it can be extended using various plugins. These plugins can provide all the necessary functionalities for development using C language. You can download Visual Studio Code for C from Microsoft’s website.

If you would like to take a look at a full installation process, I go over the steps in-depth in my fundamental C programming course. And if you are a Mac OSX user, you’re probably going to need to install XCode prior to installing any IDE.

Final Steps

Once installed your IDE, there are some common steps that you should take.

  1. Create a new project.
  2. Add a source file (.c file).
  3. Write the program in C language (based on its rules, syntax, and so forth).
  4. Use the compiler to translate (and build) the code to machine language.
  5. Run the translated code and see the results.

Hooray! Your results should be on the screen!

Hello World!
C:\Users\VladiBudnitski\source\repos\Vlad-Budnitski-Alphatech\Debug\Vlad-Budnitski-AlphaTech.exe with code 0. 

What’s next?

Congratulations! Hopefully you’ve created and successfully completed your first C Hello World Program. If you enjoyed this article, I invite you to check out my C Programming Course on Udemy.

The Complete C Programming Course has helped over 45,000 students, just like you, learn to code and master the C language. It perfectly suits students in college or university who are just getting started with no prior knowledge in programming. The class also covers advanced topics and includes plenty of exercises with full solutions.

If that sounds interesting, I’d love to see you enroll in the course. If you want to learn a bit more about C programming before you dive in, I recommend reading up on the differences between C and C++.Either way, I hope you have found this article useful. C Hello World! Enjoy!

Page Last Updated: February 2022