Skip to content

Before You Start

Welcome to the C++ Piscine! Before diving into Module 00, let’s make sure you have the foundational knowledge you’ll need to succeed.

This guide is designed for 42 students who have completed the C Piscine. You should already be familiar with:

  • Basic C programming (variables, loops, functions)
  • Pointers and memory management (malloc/free)
  • Compiling with gcc and using Makefiles
  • Working in a terminal environment

If you’re coming from C, you’re in the right place. C++ builds on C, adding powerful new features while remaining compatible with most C code.


C++ was created by Bjarne Stroustrup in 1979 as an extension of C. The ”++” in the name comes from the increment operator in C, suggesting that C++ is “C plus more.”

C++ adds several key features that make programming easier and safer:

FeatureCC++
Object-Oriented ProgrammingNoYes (classes, inheritance)
Type SafetyWeakStronger
Memory ManagementManual onlyManual + RAII
Standard LibraryLimitedExtensive (STL)
Function OverloadingNoYes
ReferencesNoYes
ExceptionsNoYes

C++ follows the principle of “you don’t pay for what you don’t use.” Features like virtual functions or exceptions only add overhead when you actually use them. This makes C++ suitable for performance-critical applications.


Throughout the C++ Piscine, you’ll learn these fundamental concepts:

OOP is a programming paradigm where you organize code around “objects” rather than functions. Think of it like this:

  • In C: You have data (structs) and functions that operate on that data
  • In C++: You have objects that contain both data AND the functions that operate on it

This bundling of data and behavior is called encapsulation.

A class is like a blueprint for creating objects. An object is an instance of a class.

Analogy: A class is like an architectural blueprint for a house. The actual houses built from that blueprint are objects. Each house has the same structure (defined by the blueprint) but can have different contents (furniture, paint colors, etc.).

C++ gives you more tools for managing memory:

  • Stack allocation: Automatic, fast, limited size (like C’s local variables)
  • Heap allocation: Manual with new/delete (replaces malloc/free)
  • RAII: A pattern where objects automatically clean up their resources

The STL provides ready-to-use containers (like dynamic arrays and hash maps) and algorithms. You won’t have to implement linked lists from scratch anymore!


Here’s a quick preview of the differences you’ll encounter:

C: printf("Hello %s\n", name);
C++: std::cout << "Hello " << name << std::endl;
C: int *arr = malloc(10 * sizeof(int));
free(arr);
C++: int *arr = new int[10];
delete[] arr;
C: char str[100];
strcpy(str, "Hello");
strcat(str, " World");
C++: std::string str = "Hello";
str += " World";
C: struct Point { int x; int y; };
struct Point p;
p.x = 10;
C++: class Point {
int x, y;
public:
Point(int x, int y) : x(x), y(y) {}
};
Point p(10, 20); // Constructor call

The C++ Piscine consists of 10 modules (00-09) plus an exam:

ModuleTopicKey Concepts
00C++ BasicsNamespaces, classes, iostream, strings
01MemoryReferences, pointers to members, file streams
02OCF & OperatorsOrthodox Canonical Form, operator overloading
03InheritanceBase/derived classes, access specifiers
04PolymorphismVirtual functions, abstract classes, interfaces
05ExceptionsTry/catch/throw, custom exceptions
06Castsstatic_cast, dynamic_cast, const_cast, reinterpret_cast
07TemplatesFunction templates, class templates
08STL Containersvector, list, map, stack, queue, iterators
09STL PracticalAlgorithms, container selection, practical applications

Each module builds on the previous ones, so complete them in order.


This documentation is organized into Guides - each guide combines theory and practical exercises for a module.

  • Concepts: What the new syntax means, why patterns exist, common pitfalls
  • Exercises: Step-by-step walkthroughs and line-by-line explanations
  • Visual diagrams and practical examples
  • Testing strategies for each exercise
  1. Read the Guide for the current module (theory section first)
  2. Read the subject PDF carefully
  3. Attempt the exercises yourself
  4. Check the exercise walkthroughs if stuck
  5. Review Common Pitfalls before evaluation

You’ll need these tools:

Use c++ or clang++ with C++98 standard:

Terminal window
c++ -Wall -Wextra -Werror -std=c++98 main.cpp -o program

The -std=c++98 flag is important! 42 requires C++98 compliance.

Use any editor you’re comfortable with. Popular choices:

  • vim/neovim
  • VS Code
  • CLion

You’ll compile and run programs from the terminal, just like in C.


These rules come from the official 42 subject PDFs. If a guide ever conflicts with the subject, follow the subject.

  • Compile with c++ and -Wall -Wextra -Werror, and keep C++98 compatibility (-std=c++98)
  • No external libraries (C++11 and Boost are forbidden)
  • Forbidden C functions: *printf(), *alloc() (malloc/calloc/realloc), and free() (grade 0)
  • using namespace ... and friend are forbidden unless explicitly allowed (grade -42)
  • STL containers/algorithms are forbidden until Modules 08 and 09 (grade -42)
  • Unless specified otherwise, output goes to stdout and ends with a newline
  • No implementation in headers (except templates), and always use include guards

From Module 02 onward, classes must follow Orthodox Canonical Form (OCF), unless explicitly stated otherwise.

Before you start, be aware of these common issues:

  1. Using using namespace std; - 42 forbids this. Always use std:: prefix.

  2. Mixing C and C++ styles - Don’t use printf when you should use std::cout. Don’t use malloc when you should use new.

  3. Forgetting the semicolon after class definition - Classes end with }; not just }

  4. Not understanding references vs pointers - Module 01 covers this in detail.

  5. Ignoring the Orthodox Canonical Form - From Module 02 onwards, every class needs proper constructors, destructor, and assignment operator.


You now have the background knowledge to start the C++ Piscine. Head to Module 00: C++ Fundamentals to begin your journey!

Remember:

  • Take your time with each module
  • Practice by writing code, not just reading
  • Use the Guides as reference
  • Don’t hesitate to re-read previous modules

Good luck! 🚀