Your First C Program: "Hello, World!"

When learning C programming, the “Hello, World!” program is traditionally your first step. It’s simple, easy to understand, and teaches the basic structure of a C program.

What Is the "Hello, World!" Program?

It’s a basic program that displays the message:

 
Hello, World!

This program helps you understand the syntax and structure of a C program.

Code: Hello World in C

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

🧪 Step-by-Step Explanation

LineExplanation
#include <stdio.h>Preprocessor directive. Includes Standard Input Output library so you can use printf()
int main()The main function – where the program starts running
{ ... }Curly braces define the body of the function
printf("Hello, World!\n");Prints text to the screen. \n means new line
return 0;Ends the program and returns control to the OS

🛠️ How to Run Hello World (Step-by-Step)

✅ On Windows (using Code::Blocks)

  1. Open Code::Blocks

  2. Create a new project → Console Application → Select C

  3. Paste the above code

  4. Click Build and Run

✅ On Linux / macOS (using terminal)

  1. Open a terminal

  2. Create a file:

     nano hello.c
  3. Paste the code

  4. Compile:

     gcc hello.c -o hello
  5. Run:

     ./hello

✅ Output

Hello, World!

🎉 Congratulations — You’ve written your first C program!

🧠 Best Practices

  • Always include comments in your code

  • Keep code indented and clean

  • Use return 0; at the end of main() to indicate successful execution

  • Use meaningful output messages as you progress

❌ Common Mistakes to Avoid

MistakeSolution
Missing semicolonAdd ; at the end of printf()
Using wrong quotesUse " " not ' ' for strings
Typo in printfMake sure spelling is correct
Forgetting #include lineRequired to use printf()