A practical overview of the C language, with examples covering pointers,
dynamic memory, structures, files and low-level programming concepts.
Use the lateral buttons to change the content displayed on the left.
This example shows a real source file, the Microsoft C compiler command
and the generated executable. The annotations identify the standard
input/output header and the final main.exe file.
A simple practical record of writing, compiling and producing an executable C program.
I want this page to show practical and understandable C examples, using
real screenshots, simple explanations and small code samples instead of a
generic or overly artificial presentation.
02 · Fundamentals
Types, conditions, loops and functions.
A strong C foundation starts with understanding primitive data types,
expressions, control flow, functions, scope and the compilation process.
Language building blocks
Main concepts
Variables store data, conditions select execution paths, loops repeat work,
and functions divide a program into reusable units.
Good practice
Readable C
Use meaningful names, small functions, explicit validation and the correct
integer types for the data being represented.
average.cfunctions and arrays
#include<stdio.h>doublecalculate_average(
constint values[],
size_t count)
{
long total = 0;
for (size_t i = 0; i < count; ++i) {
total += values[i];
}
return count == 0
? 0.0
: (double) total / count;
}
03 · Pointers and functions
Changing a variable through its address.
A pointer stores a memory address. Passing the address of a variable to a
function allows that function to modify the original value safely when the
pointer is validated before dereferencing.
Address operator
&value
Produces the memory address of value and passes it to
change_value().
Pointer parameter
int *number
Receives the address of an integer. The pointer is checked against
NULL before use.
Dereference operator
*number = 50
Accesses the integer stored at that address and changes the original
variable.
Result
10 becomes 50
The function does not return the new integer; it modifies the caller's
variable through the pointer.
pointer_function.cpointer passed to a function
#include<stdio.h>voidchange_value(int *number)
{
if (number != NULL) {
*number = 50;
}
}
intmain(void)
{
int value = 10;
printf("Before: %d\n", value);
change_value(&value);
printf("After: %d\n", value);
return0;
}
This example demonstrates pointer declaration, address passing, validation
and dereferencing in one small program.
04 · Structures
Organising related data.
Structures combine multiple fields into one type. They are useful for modelling
devices, measurements, messages, configuration records and application state.
Use . with a structure value and -> when working
through a pointer to a structure.
Design
Clear data models
Group only values that logically belong together and document units,
ownership and validity.
05 · File I/O
Reading and writing persistent data.
The C standard library provides functions to open, read, write and close files.
Every operation should be checked because files may be missing, locked or invalid.
These examples can be developed progressively and used to demonstrate
memory safety, modular design and interaction with operating-system services.
01 / CLI
Measurement data analyser
Read a CSV file, validate the values and calculate minimum, maximum and average measurements.
File I/OArraysValidation
02 / Memory
Dynamic inventory manager
Store products in a dynamically resized array using structures, pointers and explicit cleanup.
mallocreallocstruct
03 / Systems
TCP diagnostic client
Connect to a test service, send commands and validate responses using sockets and timeouts.
SocketsNetworkingError handling
07 · Online compiler
Compile and test C code online.
Compiler Explorer is excellent for comparing compilers and inspecting generated
assembly. OnlineGDB is useful for quickly executing and debugging complete console
programs in a browser.