• Home
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • TypeScript
      • Introduction to TypeScript
      • TypeScript Developer
    • React
      • Introduction to React
      • React Developer
    • Python
      • Introduction to Python
      • Python Developer
    • C++
      • Introduction to C++
      • C++ Developer
    • C Language
      • Introduction to C
      • C Developer
    • Rust
      • Introduction to Rust
      • Rust Developer
    • Zig
      • Introduction to Zig
      • Zig Developer
    • Linux Shell
      • Introduction to the Linux Shell
      • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Reading Grounds

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds
  • Featured on DanielLaunches

Courses

  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

C++ Developer -

Lesson 3 of 46

Lesson Progress: 0%

Lesson Progress: 0%
Lesson Incomplete
← Previous: References
Lesson 3 of 46
Next: Dynamic Memory →

Pointers store memory addresses and allow direct access to data in memory. They are a fundamental C++ feature that gives you low-level control over how data is stored and manipulated. Pointers support arithmetic, can be null, and can be reassigned to point to different objects. They are the backbone of dynamic memory allocation, data structures like linked lists, and array processing. This lesson covers declaring pointers, dereferencing, null checks, pointer arithmetic, and using pointers as parameters. Mastering pointers is essential for understanding how C++ manages memory at a granular level.

Code Example
#include <iostream>
using namespace std;

int main() {
    int x = 42;
    int* ptr = &x;
    cout << *ptr;
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Cpp Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • int* ptr = &x declares a pointer and stores the address of x.
  • The & operator returns the memory address of a variable.
  • The * operator dereferences the pointer to access the value at that address.
  • cout << *ptr prints the value stored at the address held by ptr.
Code Example
#include <iostream>
using namespace std;

int main() {
    int x = 10;
    int* ptr = &x;
    *ptr = 77;
    cout << x;
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Cpp Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can change the original variable by assigning through the pointer.
  • *ptr = 77 writes 77 into the memory location that ptr points to.
  • This modifies x directly because ptr holds x address.
  • Pointers give you indirect write access to any variable in scope.
Code Example
#include <iostream>
using namespace std;

int main() {
    int* ptr = nullptr;
    if (ptr == nullptr) {
        cout << "null";
    } else {
        cout << *ptr;
    }
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Cpp Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • A nullptr pointer points to nothing and should not be dereferenced.
  • Always check for nullptr before using a pointer to avoid crashes.
  • The condition ptr == nullptr checks whether the pointer is safe to use.
  • Modern C++ prefers nullptr over the older NULL macro.
Code Example
#include <iostream>
using namespace std;

int main() {
    int arr[] = {10, 20, 30};
    int* ptr = arr;
    cout << *ptr << " ";
    ptr++;
    cout << *ptr;
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Cpp Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • When a pointer points to an array, ptr++ moves to the next element.
  • Pointer arithmetic advances by the size of the pointed-to type automatically.
  • The array name arr decays to a pointer to its first element.
  • You can iterate through an array using pointer arithmetic instead of indices.
Code Example
#include <iostream>
using namespace std;

void increment(int* p) {
    (*p)++;
}

int main() {
    int x = 5;
    increment(&x);
    cout << x;
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Cpp Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • Passing a pointer to a function lets the function modify the original variable.
  • The caller passes the address with &x, and the function receives it as int* p.
  • Inside the function, (*p)++ increments the value at the pointed-to address.
  • Parentheses are necessary because *p++ would increment the pointer, not the value.
Code Example
#include <iostream>
using namespace std;

int main() {
    int x = 42;
    int* ptr = &x;
    int** pptr = &ptr;
    cout << **pptr;
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Cpp Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • A pointer to a pointer stores the address of another pointer variable.
  • Declare it with two asterisks: int** pptr = &ptr.
  • To reach the original value, use double dereference: **pptr.
  • This is used in multi-dimensional dynamic arrays and modifying pointer arguments.

Test Incomplete

What does the & operator do when applied to a variable?

Question #

1/15

Score

0/0 - 0.0 %