• Atom Feed

    Create Atom feed for your website in minutes
  • C Code Auto Indent

    Auto indent your entire C project with a simple shell command
  • C file ops

    Can you perform insert operation using C file operations? Check this C code and C file operations concepts
  • C posix signals

    Everything on Linux Signals and Signal handling, with sample code
  • Django MVC Framework

    Setting up Python Django website on Apache Shared web hosting server
  • FTP

    FTP Unix Command with examples
  • GlusterFS

    Concepts, Installation and Performance Benchmarking Reports
  • File Append in Java

    Program to perform File Append operation in Java
  • Essential Linux Commands

    Learn the basic essential linux commands in minutes
  • Loop Device in Linux

    Create loop device in Linux
  • PostgreSQL Database

    Installation and Startup Script
  • Pthreads - POSIX Multithreading

    APIs, Concepts and Sample Programs
  • Python Ctypes Module

    Intermixing C with Python and extending Python, with sample programs
  • Socket Programming

    Socket Programming in Linux explained, with TCP and UDP examples
  • String Functions in C

    Did you know string manipulation in C is so easy?
Home CPP Interview Questions

Explain dangling pointer, null pointer, void pointer, wild pointer.

States of Pointers - Null Pointer, Void Pointer, Dangling Pointer, Wild Pointer

A Pointer can be a Null Pointer or a Void Pointer or a Dangling Pointer or a Wild Pointer depending upon its state, which is defined by the operations performed on it or value it holds.

Null pointer:

Pointer assigned value NULL.

Example of null pointer:

  1. int *ptr=NULL;
  2. int *ptr = new int;
    delete ptr;
    ptr = NULL;
    // ptr is null pointer


Void pointer:

Pointer of type void which can take address assigned from any other pointer (except function pointer) and can be reassigned to other pointer type. Void pointers cannot be dereferenced. They act as place holder.

Example of void pointer:

void *ptr;


Dangling pointer:

Pointer assigned some memory and then free that memory. After freeing when not assigned to NULL it still points to same memory address, such pointer are dangling pointer.

Example of dangling pointer:

int* ptr=new int;
<some ops with ptr >
delete ptr; // at this stage, ptr is dangling pointer


Wild pointer:

Pointer which are not initialized during its definition holding some junk value( a valid address) are Wild pointer.

Example of wild pointer:

int *ptr;