Use nullptr value to mark not used pointer - C++ Data Type

C++ examples for Data Type:Pointer

Introduction

nullptr is not implicitly converted to integer types, except for bool values, where a nullptr converts to the value false.

Demo Code

#include <iostream> 

int main() //from  w ww.  ja  v  a 2  s  .  c  o  m
{ 
   int value1 = 12500; 
   int value2 = 1700; 
   int *pointer2 = nullptr; 
 
   // give pointer the address of value2 
   pointer2 = &value2; 
   // dereference the pointer and assign to value1 
   value1 = *pointer2; 
   pointer2 = 0; 
 
   std::cout << "value1 = " << value1 << "\n"; 
    
   return 0; 
}

Result


Related Tutorials