Skip to content

Module 1 · Getting Started with C — topic 1 of 4

Introduction to C

C is a compiled, general-purpose language that gives you direct control over memory and hardware. It sits underneath operating systems, databases, compilers and embedded devices.

Beginner 12 min read·Lesson 1 of 37 in C Programming

Learning objectives

  • Explain what makes C a compiled, procedural, statically typed language
  • Describe where C is used today and why
  • Compile and run a first C program

Definition

C is a statically typed, procedural, compiled programming language standardised by ISO (C89, C99, C11, C17, C23). Source code is translated by a compiler into native machine code that runs directly on the processor.

Introduction

C was created by Dennis Ritchie at Bell Labs between 1969 and 1973 to rewrite the UNIX operating system. Before C, operating systems were written in assembly language, which is tied to one processor. C made it possible to write systems software once and move it to new machines by recompiling.

Half a century later, C is still everywhere: the Linux and Windows kernels, the CPython interpreter, SQLite, Git, network routers, car engine controllers and the firmware in your keyboard. When you learn C you learn how software actually talks to hardware.

Why it matters

C forces you to understand things other languages hide: how big an int is, where a variable lives in memory, what a pointer really is and who frees memory. These ideas come up in operating systems, computer architecture, data structures and compiler design — the core subjects of a B.Tech CS degree.

C is also the common ancestor of C++, Java, C#, JavaScript and Go. Their if, for, while, braces and operators come directly from C, so the syntax you learn here transfers immediately.

Detailed explanation

C is compiled. A compiler such as GCC or Clang reads your .c file and produces an executable containing machine instructions. Nothing interprets your code while it runs, which is why C programs start instantly and run fast.

C is procedural: a program is a collection of functions that call each other, starting from a function called main. There are no classes or objects built into the language.

C is statically typed: every variable has a type (such as int or double) fixed at compile time. The compiler uses the type to decide how many bytes to reserve and which machine instructions to use.

C gives you manual memory management. You can ask for memory at run time with malloc and you must give it back with free. This power is also C's biggest source of bugs, which is why later lessons spend time on it.

StandardYearNotable additions
C89/C901989First ISO/ANSI standard
C991999// comments, bool, declarations anywhere, long long
C112011_Static_assert, threads, anonymous structs
C172018Bug-fix release of C11
C232024bool/true/false as keywords, nullptr

Syntax

C
#include <stdio.h>
int main(void) {
printf("text to print\n");
return 0;
}
  • #include <stdio.h> makes the standard input/output functions such as printf available.
  • int main(void) is where every C program starts; void means it takes no arguments.
  • printf prints formatted text; \n is a newline.
  • return 0; tells the operating system the program finished successfully.

Code examples

Hello, C

C
#include <stdio.h>
int main(void) {
printf("Hello, C!\n");
return 0;
}
Output
Hello, C!

Every statement ends with a semicolon, and the body of main is enclosed in braces.

Printing a calculation

C
#include <stdio.h>
int main(void) {
printf("%d\n", 7 * 6);
return 0;
}
Output
42

%d is a placeholder that printf replaces with an integer value.

More examples

A program with variables

C
#include <stdio.h>
int main(void) {
int year_created = 1972;
int this_year = 2026;
int age = this_year - year_created;
printf("C was created in %d.\n", year_created);
printf("In %d it is %d years old.\n", this_year, age);
return 0;
}
Output
C was created in 1972.
In 2026 it is 54 years old.

Step-by-step explanation

  • int year_created = 1972; reserves memory for an integer and stores 1972 in it.
  • int age = this_year - year_created; computes the difference at run time and stores 54.
  • The first printf substitutes year_created for %d.
  • The second printf has two %d placeholders, filled in order by this_year and age.
  • return 0; ends main and reports success.

Expected output

Running “A program with variables” prints exactly:

TextOutput
C was created in 1972.
In 2026 it is 54 years old.

Practical applications

  • Operating system kernels (Linux, FreeBSD, most of Windows) are written in C.
  • Embedded firmware in microcontrollers, medical devices and cars is mostly C.
  • Language runtimes such as CPython and Lua are written in C.
  • High-performance libraries (SQLite, OpenSSL, zlib) expose C interfaces that every other language can call.

Best practices

  • Compile with warnings turned on (-Wall -Wextra) from day one.
  • Use int main(void) and always return a value from main.
  • Keep one statement per line while you are learning; it makes compiler errors easier to locate.

Common mistakes

Forgetting the semicolon

Avoid

printf("Hi\n")
return 0;

Prefer

printf("Hi\n");
return 0;

In C a semicolon ends every statement. A missing one is a syntax error, usually reported on the line after the real mistake.

Leaving out #include <stdio.h>

Avoid

int main(void) {
printf("Hi\n");
}

Prefer

#include <stdio.h>
int main(void) {
printf("Hi\n");
}

Without the header the compiler does not know printf. Modern compilers reject the implicit declaration or warn loudly.

Important notes

  • Since C99, reaching the closing brace of main without a return behaves as return 0;, but writing it explicitly is clearer.
  • This course uses C11. Code shown here also compiles as C17 and, with rare exceptions noted in later lessons, as C23.

Key takeaways

  • C is a compiled, procedural, statically typed language standardised by ISO.
  • Execution starts in main; printf from <stdio.h> prints text.
  • C gives direct access to memory, which brings both speed and responsibility.

Try it yourself

  1. 1
    Write a program that prints your name on one line and your branch (e.g. CSE) on the next.
    Show hint

    Use two printf calls, each ending with \n.

  2. 2
    Print the product of 125 and 8 using %d without calculating it yourself.

Finished reading? Mark it complete to update your dashboard.

Suggested practice

4 questions test this exact topic. Answers and explanations are revealed after you submit.

  • BeginnerWhich statement best describes how a C program is executed?
  • BeginnerWhere does execution of every hosted C program begin?
  • BeginnerWhat does this program print?
Practise this topic