This project has been created as part of the 42 curriculum by acamelo.
C 01 shifts the focus from basic control flow to the core mechanic of the C programming language: pointers and memory address manipulation. The primary objective of this module is to demystify how variables are stored in stack memory, how to pass variables by reference to allow persistent mutation across functions, and how arrays behave as contiguous blocks of memory.
Through an intensive series of exercises, this project explores pointer dereferencing, multi-layered pointers (pointers to pointers up to
To compile and execute these programs, you require a standard C compiler (gcc or clang) installed within a UNIX-like environment.
As with previous piscine modules, these early exercises are compiled individually. Each directory contains an independent file containing the core functional logic alongside an operational main.c framework for instant verification.
- To compile a specific exercise using the standard 42 security flags:
cc -Wall -Wextra -Werror ft_ultimate_ft.c -o test_program
- To run the generated binary executable:
./test_program
Every exercise targets a specific application of pointers, addressing, or array indexing:
- **ex00:
ft_ft.c**– The fundamental introduction to pointers. Takes a pointer to an integer as a parameter and modifies the value it points to, updating it directly to42. - **ex01:
ft_ultimate_ft.c**– Introduces extreme levels of memory indirection by taking a pointer to a pointer (up to 9 levels:int *********) and dereferencing through all layers to modify the underlying integer value. - **ex02:
ft_swap.c**– Leverages pointer-based passing by reference to swap the values of two integers stored at different memory addresses using a temporary holding variable.
- **ex03:
ft_div_mod.c**– Divides two integers and stores the resulting quotient and remainder directly into two separate memory addresses passed as pointer parameters. - **ex04:
ft_ultimate_div_mod.c**– Performs the same division and modulo operation, but optimizes memory usage by overwriting the initial values stored inside the parameters themselves.
- **ex05:
ft_putstr.c**– Displays a string of characters to the standard output by iterating through an array of chars via character pointers until it hits the null-terminator (\0). - **ex06:
ft_strlen.c**– Replicates the standardstrlenfunctionality by counting and returning the total number of characters in a string by tracking pointer offsets until the null-terminator is reached.
- **ex07:
ft_rev_int_tab.c**– Reverses the order of elements within an integer array in-place. It utilizes two distinct pointer boundaries (start and end indexes) that move inward toward the center of the memory block.
Developing ft_ultimate_ft requires tracing how the stack handles nested memory addresses. A common mistake when managing multiple pointer levels is losing track of the asterisk syntax or mismatching assignments. The function safely reaches the baseline data segment by applying nine consecutive dereferences (*********p = 42;), which forces the hardware to traverse the nested memory references step-by-step until it updates the target integer.
When reversing an integer array in ft_rev_int_tab, memory constraints prohibit allocating a secondary array to hold values. To solve this efficiently, an in-place dual-pointer swapping strategy was applied. By initializing a pointer at index 0 and another at size - 1, elements are swapped using a single temporary variable while moving both index pointers inward. The loop terminates seamlessly when the pointers meet or cross at the center (
- C Memory Model Layouts: Studied stack frame allocation behavior to fully grasp how local variables lose scope while variables passed via pointers retain mutations across function boundaries.
- Pointer Arithmetic Manuals: Reviewed how array tracking (
tab[i]) functions under the hood as direct pointer notation updates (*(tab + i)). - Cluster Peer Feedback: The 42 Madrid cluster was an excellent testing ground to swap boundary test scripts, verifying that edge cases—such as passing empty strings to
ft_strlenor zero-sized arrays toft_rev_int_tab—did not cause segmentation faults.
Artificial Intelligence was integrated into this project as a structural and educational advisor under the following rules:
- Memory Trace Analysis: Used to mentally map out complex multi-pointer references and verify code flow safety under strict compiler warnings.
- Technical Editing: AI assisted in organizing, structuring, and polishing this technical
README.mdto ensure a cohesive presentation for recruiters ahead of the Web Summit. - Note: Every single line of code was written manually, line-by-line, adhering strictly to the 42 Norm guidelines.