C programming portfolio

C for systems and hardware.

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.

01 · Practical example

Compiling a basic C program on Windows.

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.

C source code and Microsoft compiler output with annotations
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.c functions and arrays
#include <stdio.h>

double calculate_average(
    const int 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.c pointer passed to a function
#include <stdio.h>

void change_value(int *number)
{
    if (number != NULL) {
        *number = 50;
    }
}

int main(void)
{
    int value = 10;

    printf("Before: %d\n", value);
    change_value(&value);
    printf("After: %d\n", value);

    return 0;
}
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.

sensor.c struct example
#include <stdio.h>

typedef struct {
    unsigned int id;
    double temperature;
    int is_valid;
} SensorReading;

void print_reading(const SensorReading *reading)
{
    if (reading == NULL || !reading->is_valid) {
        return;
    }

    printf(
        "Sensor %u: %.2f C\n",
        reading->id,
        reading->temperature);
}
Access

Dot and arrow operators

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.

log_writer.c safe file handling
#include <stdio.h>

int write_result(const char *path, double value)
{
    FILE *file = fopen(path, "a");

    if (file == NULL) {
        return -1;
    }

    const int result =
        fprintf(file, "measurement=%.3f\n", value);

    if (fclose(file) != 0) {
        return -1;
    }

    return result < 0 ? -1 : 0;
}
06 · Projects

Ideas for practical C projects.

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/O Arrays Validation
02 / Memory

Dynamic inventory manager

Store products in a dynamically resized array using structures, pointers and explicit cleanup.

malloc realloc struct
03 / Systems

TCP diagnostic client

Connect to a test service, send commands and validate responses using sockets and timeouts.

Sockets Networking Error 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.