</>
Skip to content
C lessons (3/28)

C — Get Started

What is C?

C is the foundation of modern programming. Created in 1972 by Dennis Ritchie at Bell Labs, it gave birth to C++, Java, Python, JavaScript, and almost every language that followed.

C gives you direct access to memory and hardware. It's the language of operating systems (Linux, Windows kernels), databases (MySQL, PostgreSQL), and embedded devices.

Install a compiler

You need a C compiler. The most common is GCC (GNU Compiler Collection):

Windows

  1. Install MinGW-w64
  2. Add the bin folder to your PATH
  3. Verify: gcc --version

Mac

xcode-select --install

Linux

sudo apt install gcc

Your first program

Create hello.c:

#include <stdio.h>

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

Compile and run:

gcc hello.c -o hello
./hello        # or hello.exe on Windows

Output:

Hello, world!

Understanding the code

#include <stdio.h>    // includes the Standard Input/Output library

#include is a preprocessor directive — it copies the contents of stdio.h into your file before compilation.

int main() {          // program entry point
    printf("Hello\n"); // prints text to the console
    return 0;          // returns 0 to the operating system
}

main() is special — it's where every C program starts executing. return 0 signals success to the OS.

Compiling

C is a compiled language — the compiler converts your code to machine code before it runs:

source code (.c) → compiler → executable (a.out or hello)

This two-step process means C programs are fast — no interpreter overhead at runtime.

The compilation process

1. Preprocessing — handles #include, #define, macros
2. Compilation — converts to assembly language
3. Assembly — converts to machine code (object files)
4. Linking — combines object files into an executable

You can see each step with flags:

gcc -E hello.c -o hello.i    # preprocessing only
gcc -S hello.c -o hello.s    # compilation to assembly
gcc -c hello.c -o hello.o    # compilation to object file
gcc hello.o -o hello          # linking

Useful compiler flags

gcc -Wall hello.c -o hello     # enable all warnings
gcc -Werror hello.c -o hello   # treat warnings as errors
gcc -g hello.c -o hello        # include debug information
gcc -O2 hello.c -o hello       # optimize for speed
gcc -std=c11 hello.c -o hello  # use C11 standard

Always use -Wall — warnings catch bugs before they become problems.

Basic output

#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    printf("Name: %s\n", "Ada");
    printf("Age: %d\n", 36);
    printf("Pi: %.2f\n", 3.14159);
    return 0;
}

printf uses format specifiers:

SpecifierTypeExample
%dint42
%ffloat/double3.14
%cchar'A'
%sstring"hello"
%ppointer0x7fff5fbff8b0
%ldlong int9000000000L
%luunsigned long9000000000UL
%%literal %%

Basic input

#include <stdio.h>

int main() {
    int age;
    printf("How old are you? ");
    scanf("%d", &age);
    printf("You are %d years old.\n", age);
    return 0;
}

scanf reads input from the terminal. The & before age passes the variable's address — required for scanf to modify it.

Header files

#include <stdio.h>   // input/output: printf, scanf, FILE operations
#include <stdlib.h>  // general: malloc, free, rand, exit
#include <string.h>  // strings: strlen, strcpy, strcmp
#include <math.h>    // math: sqrt, pow, sin, cos
#include <ctype.h>   // character: isalpha, isdigit, toupper
#include <time.h>    // time: time(), clock()

Each header provides a set of functions. Include only what you need.

Project structure

Simple programs use one file. Real projects use multiple files:

project/
  main.c          # entry point
  utils.c         # utility functions
  utils.h         # function declarations
  Makefile        # build instructions
// utils.h
#ifndef UTILS_H
#define UTILS_H

int add(int a, int b);
double average(double arr[], int size);

#endif
// utils.c
#include "utils.h"

int add(int a, int b) {
    return a + b;
}

Mini Practice

  1. Install GCC and verify with gcc --version
  2. Write a program that prints your name, age, and favorite language
  3. Use scanf to read a number and print its square
  4. Compile with -Wall and fix any warnings
  5. Create a program that prints the current date using time.h

Next: C syntax rules →

Related Topics

Frequently Asked Questions about Get Started

What is Get Started in C?

Get Started is a fundamental concept in C. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Get Started?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Get Started.

Why is Get Started important in C?

Get Started is essential for C development. Understanding this concept will help you write better code and solve real-world problems more effectively.