Loading...

C essentialsGetting Started

Introduction to C

Introduction to C illustration

5 min lesson

Next
  • C is a general-purpose programming language created in the early 1970s by Dennis Ritchie at Bell Labs.
  • It is small, fast, and gives you direct control over memory, which is why it is used in operating systems, embedded devices, and game engines.
  • C is often called a "middle-level" language because it combines low-level memory access with high-level readable syntax.
  • A compiler translates C source code into machine code that the computer's processor can execute directly.
  • C has a small set of keywords (about 32) and relies on a standard library for common tasks like printing text or doing math.
  • Many modern languages (C++, Java, Python, JavaScript) borrow syntax and ideas from C, so learning C makes them easier later.
  • The C standard library provides functions like printf for output and malloc for memory, but you must include the right header files.
  • C is statically typed: every variable has a fixed type (like int or float) that tells the computer how much memory to reserve.
  • C is compiled, not interpreted: you write code, run a compiler, and get an executable file.
  • Understanding C helps you understand what really happens inside the computer when a program runs.
  • In this lesson there is no code, because C is best learned by writing and running programs, which start in the next lessons.
Keep in mind
  • C is a fast, small, compiled language that gives you control over memory.
  • It is the foundation of many modern languages and operating systems.
  • Every C program must be compiled before it can run.
  • Do not worry about memorizing everything now; you will learn by writing small programs step by step.

Breaking it down

Compiled language

gcc program.c -o program

C code is translated by a compiler into an executable file before it runs. This makes C programs fast because the computer does not need to translate while running.

Static typing

int age = 25;

Every variable must have a type that tells the compiler how much memory to set aside and what operations are allowed. This catches many mistakes before the program runs.

Standard library

#include <stdio.h>

C itself has very few built-in features. The standard library gives you ready-made functions for input/output, math, strings, and more, but you must include the right header.

Low-level access

int *ptr = &age;

C lets you work with memory addresses directly using pointers. This is powerful but requires care to avoid bugs.

A helpful analogy

C is like a simple, reliable toolbox with a few sharp tools. It does not hide anything from you: you see every screw and bolt (memory, types), and you decide how to use them. That makes it powerful but also means you must handle the tools carefully.

Nesting rules

  • 1.Every C program must have exactly one main function, which is where execution begins.
  • 2.C is case-sensitive: int and Int are different, so always match the exact spelling of keywords and names.
  • 3.Statements end with a semicolon (;). Missing semicolons are a very common beginner error.

Common mistakes

Thinking C is interpreted like Python

Avoid

Running program.c directly in a terminal

Use instead

gcc program.c -o program && ./program

C must be compiled first. The computer cannot run C source code directly; it needs a compiled executable.

Forgetting that C is case-sensitive

Avoid

Int age = 5;

Use instead

int age = 5;

Int (capital I) is not a keyword, so the compiler will report an unknown type error. Always use lowercase int.

Expecting C to handle memory automatically like garbage-collected languages

Avoid

Creating memory and never freeing it

Use instead

free(ptr);

C does not clean up memory for you. You must manually free what you allocate with malloc, or you get a memory leak.

Quick tips

  • •Do not try to memorize all of C at once. Write one small program per day and run it.
  • •Read compiler error messages from top to bottom; the first error often causes later ones.
  • •Keep a cheat sheet of keywords and standard library functions as you learn them.
  • •Experiment: change a value in a program and see how the output changes. This builds intuition.
  • •When you are stuck, simplify: comment out lines until the program compiles, then add them back one by one.
Next