# Introduction to C — First Program, Compilation and Program Structure

Source: https://skills101.in/learn/c-programming/c-introduction — Skills101 free tutorial (C Programming). Updated 2026-11-09.

**C** is one of the oldest popular languages (1972), and it's still everywhere: operating systems (Linux, Windows kernels), embedded devices, databases and the Python interpreter itself are written in C. Learning C teaches you **how computers really work** — memory, addresses, bytes.

## 1. Your first program

```c
#include <stdio.h>

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

```text
Hello, Skills101!
```

| Line | Meaning |
|---|---|
| `#include <stdio.h>` | include the standard input/output library (for `printf`) |
| `int main(void)` | execution starts here; returns an `int` |
| `printf("…\n")` | print text; `\n` is a new line |
| `return 0;` | tell the operating system "finished successfully" |

Every statement ends with `;`. Blocks are inside `{ }`. C is **case-sensitive** (`Main` ≠ `main`).

## 2. How a C program is compiled

![hello.c passes through the preprocessor (#include, #define), the compiler (C to assembly), the assembler (object file) and the linker (adds libraries) to make an executable](https://skills101.in/learn-img/c-programming/compile-pipeline.svg)

1. **Preprocessor** — handles lines starting with `#`: pastes in header files, replaces macros.
2. **Compiler** — turns C into assembly and checks syntax and types.
3. **Assembler** — turns assembly into machine code (object file `.o`).
4. **Linker** — joins your object files with libraries (like the code for `printf`) into an executable.

With GCC: `gcc hello.c -o hello` then `./hello` (Linux/Mac) or `hello.exe` (Windows). Beginners on Windows can install **MinGW** or use an online compiler — or our [coding practice](https://skills101.in/practice/code).

## 3. Printing numbers

```c
#include <stdio.h>

int main(void) {
    int marks = 92;
    float cgpa = 8.75f;
    printf("Marks: %d\n", marks);
    printf("CGPA: %.2f\n", cgpa);
    printf("Sum: %d\n", 10 + 5);
    return 0;
}
```

```text
Marks: 92
CGPA: 8.75
Sum: 15
```

`%d`, `%f` are **format specifiers** — placeholders replaced by the values after the comma. More in the next lesson.

## 4. Comments

```c
// single-line comment (C99 and later)
/* multi-line
   comment */
```

## 5. Structure of a C program

```text
/* documentation: what this program does */
#include <stdio.h>          ← header files
#define PI 3.14159          ← macros / constants
int count = 0;              ← global variables
int square(int n);          ← function declarations (prototypes)

int main(void) {            ← main function
    ...
    return 0;
}

int square(int n) {         ← other function definitions
    return n * n;
}
```

## 6. Why C is "middle level"

C has high-level features (functions, loops, structures) but also low-level access (pointers, memory addresses, bits). It is **fast** because it compiles to machine code and does very little checking at runtime — which also means **you** must be careful (no automatic bounds checks).

## Common mistakes

- Forgetting `#include <stdio.h>` → warnings or errors for `printf`.
- Missing semicolons or the `\n` at the end of output.
- Writing `void main()` — the standard is `int main(void)` returning 0.

## Quick recap

- C is fast, close to hardware, and used in OS and embedded systems.
- Preprocessor → compiler → assembler → linker.
- `main` is the entry point; `printf` with format specifiers prints values.
- Statements end with `;`; C is case-sensitive.


Practice quiz and free certificate: https://skills101.in/learn/c-programming/c-introduction