Last active
November 26, 2016 19:09
-
-
Save illescasDaniel/f762e7792ca0ce3af94314ddd6c990bb to your computer and use it in GitHub Desktop.
Check null pointer with an assertion [C++]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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