Introduction to C

Introduction

C is a general-purpose programming language created in the early 1970s at Bell Labs by Dennis Ritchie. It was built to write operating systems and low-level software, and it still powers a huge part of the computing world today.

You will find C inside operating systems (Linux, Windows kernels), embedded devices, game engines, databases, and compilers for other languages. If you learn C, you get a clear picture of how computers actually run your code.

Syntax

Every C program needs a starting point. That entry point is the main function:

PartWhat it does
#include <stdio.h>Brings in the standard input/output library so you can use printf
int main()The function where execution starts
printf(...)Prints text to the screen
return 0;Tells the OS the program finished without errors

Parameters or Components

A small C program is made of a few building blocks. You do not need all of them on day one, but it helps to know the names:

ComponentRole
Preprocessor directivesLines like #include that run before compilation
FunctionsNamed blocks of code you can call, starting with main
VariablesNamed storage for data (covered in the next lessons)
StatementsInstructions that end with a semicolon
CommentsNotes for humans; the compiler ignores them

Basic Example

Output

When you run the program above, the screen shows:

C was born around 1972

Code Explanation

  1. We include stdio.h so printf is available.
  2. Inside main, we create an integer variable year and set it to 1972.
  3. printf prints text. The %d placeholder is replaced by the value of year.
  4. return 0 ends the program successfully.

More Examples

Printing multiple lines

Simple math in C

Real-World Usage

Teams pick C when they need speed, direct hardware access, or a language that compiles almost anywhere. The Linux kernel, SQLite, Redis, and many microcontroller firmware projects are written in C or heavily influenced by it.

  • Operating systems — kernels and drivers
  • Embedded systems — microcontrollers in cars, appliances, IoT
  • Compilers & interpreters — Python, PHP, and others often have C under the hood
  • High-performance tools — databases, game engines, network stacks

Common Mistakes

Forgetting semicolons. Most statements in C end with ;. Missing one usually gives a confusing error on the next line.

Skipping return 0 in main. Many compilers still build your program, but returning a value from main is good practice and required in some environments.

#include <stdio.h>

int main() {
    printf("Hello")   /* ERROR: missing semicolon */
    return 0;
}

Best Practices

  • Keep main short — call other functions for bigger tasks
  • Use clear names: studentCount beats x
  • Compile often so errors stay small and easy to fix
  • Add comments when the why is not obvious from the code

Tips

Interview tip: Interviewers often ask what printf returns (it returns the number of characters printed) or where program execution begins (main).

Install a C compiler (GCC or Clang) and run your first program today. Typing code yourself — even hello world — sticks better than only reading.

Summary

  1. C is a compiled language used for systems, embedded, and performance-critical software.
  2. Every program starts in main.
  3. #include pulls in library code; printf prints output.
  4. Statements end with ;; return 0 signals success.

Ready to test what you learned?

23 exercises · earn XP · 0 completed