Learning path

Full curriculum

Full curriculum

Unit content

C programming

C is a compiled programming language designed around a small set of abstractions that map closely to machine data and memory.

This unit focuses on what is specific to C rather than repeating general programming concepts such as variables, expressions, loops and functions.

Translation and execution

A C source file contains declarations, function definitions and preprocessor directives. A typical toolchain preprocesses and compiles the source into object code, then links object files and libraries into an executable.

For example:

#include <stdio.h>

int main(void) {
    int x = 3;
    printf("%d\n", x + 1);
    return 0;
}

Static types

Objects and expressions have types such as char, int, float, double and programmer-defined aggregate types. Types determine properties such as representation, permitted operations and how expressions are interpreted.

C also exposes implementation-dependent details that many higher-level languages hide. The exact width of an int, for example, is not fixed to one universal number of bits, although the standard imposes minimum ranges and ordering constraints.

Declarations and scope

A declaration introduces an identifier and its type. Definitions allocate storage or provide function bodies. C distinguishes block scope, file scope and linkage between translation units.

Functions

Functions have explicitly declared parameter and return types:

int square(int x) {
    return x * x;
}

Arguments are passed by value. When a function needs to modify an object owned elsewhere, C normally passes the object's address through a pointer.

Arrays and strings

An array stores a fixed number of elements of one type contiguously:

int values[4] = {2, 4, 6, 8};

C strings are arrays of char terminated by a zero byte. The language does not attach an independent run-time length to an ordinary C string, so code must respect the allocated bounds.

Explicit responsibility

C deliberately provides few automatic run-time checks. Operations that exceed an object's bounds, use invalid addresses or violate object lifetimes can produce undefined behavior rather than a managed-language exception.

That low-level control is useful for systems programming, but it makes memory representation and pointers central parts of competent C programming.