Null Pointer Example in C++


The program assigns a null value to an integer pointer ptr and prints the value of ptr using the cout statement. Here's what the program does step by step:

  • Declare an integer pointer ptr.
  • Assign a null value to ptr using the NULL macro.
  • Print the value of ptr using the cout statement.

Source Code

#include<iostream>
using namespace std;
int main()
{
  int *ptr = NULL;
  cout<<"The value of ptr is "<<ptr;
  return 0;
}
To download raw file Click Here

Output

The value of ptr is 0

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples