Random Stuff with Pointers (in C++)!
DynamicSquid (101)

What's a pointer?

This isn't meant to be a pointer tutorial, but just a quick recap:

Pointers store memory addresses!

What if they don't?

But what happens if you don't initialize a pointer? Does it point to nothing? Let's find out!

Test

int* pointer1;
int* pointer2 = NULL;

if (pointer1) // evaluates to true if pointer is not NULL
  std::cout << "Pointer1 contains random memory address";
if (pointer2)
  std::cout << "Pointer2 contains no address";

Output:

Pointer1 contains random memory address

Result

As you can see, if you don't initialize a pointer, then it doesn't contain nothing, but instead a random address!

So always initialize your pointers!

You are viewing a single comment. View All