home
clear breadcrumbs
search
login
 
null pointers
#include < iostream > using namespace std; int main() { int* num_ptr{ nullptr }; // we initialize a pointer to point nowhere num_ptr = new int; // we allocate memory for an integer on the heap // and stores the address in the pointer num_ptr cout << &num_ptr << endl; // this will show us the address of the new // int we just created cout << *num_ptr << endl; // since we didn't initialize the variable // we will get garbage data here *num_ptr = 25; // initializing to 25 cout << *num_ptr << endl; // 25 will be displayed now instead of the // garbage that was displayed before we // initialized } }