C Introduction

C · Lesson 1 of 32 8 min read Updated

The phone in your pocket, the ATM at the corner, the Wi-Fi router at home and the software inside a car's engine all have something in common: a large part of their code is written in C. C is more than fifty years old, yet it still runs much of the world's computing.

In this lesson you will learn what C is, where it is used, how a C program turns into something your computer can run, and what makes C different from languages such as Python and Java.

What is C?

C is a general-purpose programming language. Dennis Ritchie created it at Bell Labs in the early 1970s, mostly in 1972, so that he and Ken Thompson could rewrite the Unix operating system in a language that was easier to work with than assembly code but still fast.

Three ideas describe C well:

  • Compiled. You write C in a text file. A program called a compiler translates it into machine code, the instructions your processor understands directly. The result is a separate program file you can run again and again.
  • Small and close to the hardware. C has only a few keywords and a small standard library. It lets you work with memory addresses directly through pointers, which is why people sometimes call it "portable assembly".
  • Procedural. A C program is built from functions, named blocks of code that each do one job. C has no classes or objects like Java has.

Here is a complete C program. Do not worry about every symbol yet; the next lessons explain each line.

C
#include <stdio.h>

int main(void)
{
    printf("Namaste from Pune!\n");
    return 0;
}
Output
Namaste from Pune!

printf prints text on the screen, \n moves to a new line, and return 0; tells the operating system that the program finished without errors.

Where is C used today?

C is everywhere that speed, small size or direct control of hardware matters. Some well-known examples:

AreaExamples written mainly in C
Operating systemsThe Linux kernel, large parts of Windows and macOS
Embedded devicesMicrocontrollers in washing machines, cars, routers and medical devices
DatabasesSQLite, PostgreSQL, Redis
Programming languagesCPython (the standard Python interpreter), the PHP interpreter
Tools and serversGit, curl, the nginx web server

When you run a Python script, the interpreter that runs it is a C program. When you push code with Git, C code does the work. Learning C helps you understand what is happening underneath the tools you already use.

How a C program runs

Python reads your code and runs it line by line through an interpreter. C works differently. You first compile the whole program, and then you run the result.

  1. You write source code in a file that ends in .c, for example hello.c.
  2. The compiler (GCC or Clang) checks it for errors and translates it into machine code.
  3. The compiler produces an executable, a file such as hello on Linux and macOS or hello.exe on Windows.
  4. You run the executable. It no longer needs the compiler or the source file.

In a terminal, the two steps look like this:

Terminal
gcc -std=c23 -Wall -Wextra hello.c -o hello
./hello

The first command compiles hello.c into a program called hello. The second command runs it. You will install a compiler in Install GCC/Clang & VS Code and learn what every part of this command means in Your First C Program.

Because the translation happens before the program runs, a compiled C program starts instantly and runs very fast. The cost is that you must compile again every time you change the code.

A slightly bigger program

Programs become useful when they store values and calculate with them. This one works out a batsman's strike rate, which is the runs scored for every 100 balls faced.

C
#include <stdio.h>

int main(void)
{
    int runs = 48;
    int balls = 32;
    double strike_rate = runs * 100.0 / balls;

    printf("Rohan scored %d runs off %d balls.\n", runs, balls);
    printf("Strike rate: %.2f\n", strike_rate);
    return 0;
}
Output
Rohan scored 48 runs off 32 balls.
Strike rate: 150.00

int stores whole numbers and double stores numbers with a decimal point. Inside printf, %d is replaced by a whole number and %.2f by a decimal number with two digits after the point. Every C program you write will use ideas like these.

C compared with Python and Java

FeatureCPythonJava
How it runsCompiled to machine codeRun by an interpreterCompiled to bytecode, run by the JVM
TypesStatic: you declare each variable's typeDynamic: types are checked while runningStatic
MemoryYou request and free memory yourselfAutomatic (garbage collector)Automatic (garbage collector)
Safety checksVery few; no array bounds checkingManyMany
Typical speedVery fastSlowerFast

C trusts the programmer. If you read past the end of an array, C does not stop you. The program may print rubbish, crash, or quietly corrupt data. These memory bugs are behind many security problems in real software, so this course teaches safe habits from the start: turning on compiler warnings, using size-limited functions and checking every input.

Versions of C

C has changed over the years through official standards, documents that define exactly what the language means. The main versions are K&R C (1978), C89/C90, C99, C11, C17 and C23, the current standard, published in 2024. This course teaches C23 and points out where older code you may meet in books, exams or projects looks different. You can read the full story in C Standards: K&R to C23.

Why learn C?

  • You learn how memory, pointers and the stack really work, which makes you better in every other language.
  • Syntax from C appears in C++, Java, JavaScript, C# and PHP: braces, semicolons, for loops and if statements all look similar.
  • C is the main language for embedded systems and operating system work.
  • Many university courses and technical interviews test C concepts such as pointers and memory.

Common misunderstandings

  • "C is old, so it is dead." C is still updated, and the C23 standard added many modern features. New systems code is written in C every day.
  • "C is the same as C++." They share history and syntax, but they are separate languages with separate standards.
  • "If it compiles, it is correct." A C compiler accepts many programs that are wrong. Warnings and testing are essential.

Key points

  • C is a compiled, procedural, general-purpose language created by Dennis Ritchie at Bell Labs around 1972.
  • A compiler turns .c source files into an executable that runs directly on the processor.
  • C powers operating systems, embedded devices, databases and interpreters such as CPython.
  • C gives you direct control of memory but performs very few safety checks, so careful habits matter.
  • C23 is the current standard; this course teaches it and shows the older forms you will still see.

Exercise

Look at the strike-rate program above. Without running anything, write down what the output would be if runs were 75 and balls were 50. Then list two pieces of software you use every week that are written mainly in C.

Show solution

With 75 runs off 50 balls, the strike rate is 75 × 100 / 50 = 150, so the output is:

Output
Rohan scored 75 runs off 50 balls.
Strike rate: 150.00

Possible answers for the second part: Git, the Python interpreter (CPython), SQLite inside your phone's apps, or the Linux kernel inside an Android phone.

Quick Quiz

1. Who created the C language?

2. What does a C compiler do?

3. Which statement about C is true?

4. What is the current C standard taught in this course?

Learn C with a mentor

Free lessons get you started. Our Java, C & C++ Programming training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call