Skip to content

Instantly share code, notes, and snippets.

@illescasDaniel
Last active November 26, 2016 19:09
Show Gist options
  • Save illescasDaniel/f762e7792ca0ce3af94314ddd6c990bb to your computer and use it in GitHub Desktop.
Save illescasDaniel/f762e7792ca0ce3af94314ddd6c990bb to your computer and use it in GitHub Desktop.
Check null pointer with an assertion [C++]
#include <iostream>
#include <cstddef>
#include <cassert>
using namespace std;
int main(int argc, char *argv[]) {
int * numbers = nullptr; // = new int[3]{1,2,3};
assert(numbers && "Error, null pointer");
cout << numbers << endl;
delete[] numbers;
numbers = nullptr;
cout << numbers << endl; // Check address
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment