02 - C Getting Started - Installation and First Program

Install a C compiler and write your first Hello World program


What is this topic?

This guide explains C Get Started - Installation and Your First Program in simple terms, what it does, and how to use it in real C programs.

Why We Need It

  • It helps you write correct and reliable C code.
  • It makes your programs easier to read and maintain.
  • It is used in real projects and interviews.
  • It reduces common beginner mistakes.
  • It builds a strong foundation for advanced topics.

Use Cases

  • Building practical C programs step by step.
  • Solving real coding tasks with clean logic.
  • Preparing for exams, interviews, and projects.
  • Understanding and improving existing C code.

What You Need

Before you start programming in C, you need a compiler. A compiler is a tool that converts your C code into a language computers understand.

The Three Things You Need:

  1. Text Editor - Write your code (Notepad++, VS Code, etc.)
  2. C Compiler - Convert code to executable programs
  3. Terminal/Command Prompt - Run your programs

Installation Guide by Operating System

For Windows Users

Option 1: MinGW (Recommended for Beginners)

Step 1: Download MinGW

Step 2: Install MinGW

  • Run the installer
  • Click “Install”
  • Choose installation location (remember it!)
  • Complete the installation

Step 3: Add to System Path

  • Right-click “This PC” → Properties
  • Click “Advanced system settings”
  • Click “Environment Variables”
  • Under “System variables,” select “Path”
  • Click “Edit”
  • Click “New”
  • Paste: C:\MinGW\bin (or your install location)
  • Click OK and restart your computer

Step 4: Verify Installation

  • Open Command Prompt
  • Type: gcc --version
  • You should see version information

Option 2: Dev-C++


For Mac Users

Step 1: Install Xcode Command Line Tools

  • Open Terminal
  • Type: xcode-select --install
  • Click “Install”
  • Accept license agreement

Step 2: Verify Installation

  • Type: gcc --version
  • You should see version information

For Linux Users

Step 1: Install GCC

For Ubuntu/Debian:

sudo apt-get update
sudo apt-get install gcc

For Fedora:

sudo dnf install gcc

Step 2: Verify Installation

gcc --version

Your First Program: Hello World

Now let’s write your first C program!

Step 1: Create a File

Create a new file called hello.c in a folder on your computer.

Windows:

  • Open Notepad
  • Click File → New
  • Save as hello.c

Mac/Linux:

  • Open Terminal
  • Type: nano hello.c

Step 2: Write Your First Program

Copy this code into your file:

#include <stdio.h>

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

Step 3: Save Your File

Save the file as hello.c

Step 4: Open Terminal/Command Prompt

Windows:

  • Press Windows + R
  • Type cmd
  • Press Enter

Mac/Linux:

  • Press Cmd + Space
  • Type Terminal
  • Press Enter

Step 5: Navigate to Your File

cd Desktop

(If your file is on Desktop, or replace Desktop with your folder name)

Step 6: Compile Your Code

gcc hello.c -o hello

This creates an executable file called hello

Step 7: Run Your Program

Windows:

hello.exe

Mac/Linux:

./hello

Expected Output:

Hello, World!

Congratulations! You’ve written and run your first C program! :tada:


Understanding Your First Program

Let’s break down what each line does:

#include <stdio.h>
  • Includes the Standard Input/Output library
  • Lets us use printf() function
int main() {
  • Defines the main function
  • Every C program starts here
  • int means it returns an integer value
    printf("Hello, World!");
  • Prints text to the screen
  • The text must be in quotes
  • Don’t forget the semicolon at the end!
    return 0;
  • Exits the program
  • Returns 0 to the system (means success)
}
  • Closes the main function

Common Installation Issues

Issue: “gcc: command not found”

  • Your compiler isn’t installed correctly
  • Restart your computer after installation
  • Check that MinGW was added to your system path

Issue: “Error: file not found”

  • Make sure your .c file is in the same folder as your terminal
  • Use ls (Mac/Linux) or dir (Windows) to list files
  • Make sure you’re in the right directory

Issue: “Compilation failed”

  • Check for typos in your code
  • Make sure you have all the required headers
  • Verify semicolons are present

Alternative: Use an Online Compiler

If installation is too difficult, you can use an online C compiler:

Popular Options:


Now What?

You’re ready to learn C! Let’s move on to the basics.


:books: Navigation

Previous Next
← C Intro C Syntax →

:red_question_mark: Have Questions?

Comment below and we’ll help you! Did you get your first program working? Share your questions or let us know if you hit any issues.