noknow.dev
Sign inSign up
Course overview
C++ Fundamentals
0 / 39 lessons0%

Getting Started

  • Hello, World!
  • Variables and Data Types
  • Arithmetic and Operators
  • Working with std::string
  • Type Conversion and Casting

Control Flow

  • if / else if / else
  • switch / case
  • while and do-while Loops
  • for Loops
  • break, continue, and Finding Primes

Functions

  • Writing Functions
  • Pass by Value vs. Pass by Reference
  • Overloading and Default Parameters
  • Recursion

Arrays and Strings

  • C-style Arrays
  • std::vector — Dynamic Arrays
  • std::string Deep Dive
  • 2D Arrays and Matrices

Pointers and Memory

  • Memory Addresses and Pointers
  • Dynamic Memory: new and delete
  • References vs Pointers

Object-Oriented Programming

  • Classes and Objects
  • Constructors and Destructors
  • Inheritance
  • Virtual Functions and Polymorphism
  • Operator Overloading

The Standard Template Library

  • std::vector in Depth
  • std::map and std::unordered_map
  • std::set and Sorted Unique Collections
  • STL Algorithms

Templates and Generic Programming

  • Function Templates
  • Class Templates

Modern C++ (C++11/14/17)

  • auto and Range-based for
  • Lambda Functions
  • Smart Pointers
  • Move Semantics

Error Handling and Exceptions

  • try / catch / throw
  • Custom Exception Classes
  • RAII and Resource Management

Dynamic Memory: new and delete

0m 00s

Heap Allocation

Local variables live on the stack and are freed automatically. new allocates on the heap — it persists until you delete it:

int* p = new int(42);
cout << *p;    // 42
delete p;       // free the memory — ALWAYS do this!
p = nullptr;    // good practice

int* arr = new int[10];
arr[0] = 5;
delete[] arr;   // note: delete[] for arrays, not delete

Common pitfalls

  • Memory leak — allocate but forget to delete
  • Double delete — calling delete twice → crash
  • Dangling pointer — using a pointer after deleting it

In modern C++, prefer unique_ptr / shared_ptr (covered in Chapter 9) over raw new/delete.

Your Task

Write createArray(int size, int fillVal) that allocates a heap array of size ints, fills each with fillVal, and returns the pointer.

Back
cppCtrl+Enter to run
Output

Click "Run" to execute your code.