1 / 6

Types of Pointers

Types of Pointers. An Introduction. Types of Pointers. Generic Pointer NULL Pointer Wild Pointer Dangling Pointer. Generic Pointer. Generic pointer is also known as void pointer. Generic pointer is a special type of pointer which points to the data of no specific data type

errol
Download Presentation

Types of Pointers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Types of Pointers An Introduction

  2. Types of Pointers • Generic Pointer • NULL Pointer • Wild Pointer • Dangling Pointer

  3. Generic Pointer • Generic pointer is also known as void pointer. • Generic pointer is a special type of pointer which points to the data of no specific data type • For example void *ptr; • Here ptr is a generic pointer. • We can assign the address of any data type to generic pointer after its declaration. • We use generic pointer in two situations. One when we have no idea in advance about the data type of the variable. • Secondly when we have to assign the address of different variables of different data types to the single pointer.

  4. NULL Pointers • It is a special type of pointer which points nowhere. • It is usually used to know if the pointer points to null or free the memory during the deallocation of memory in dynamic memory location. • For Example: int *ptr= NULL;

  5. Wild Pointers • An uninitialization pointer is known as wild pointer. • Wild pointer holds a garbage value. • It is not pointing any memory location yet. • For Example: int *ptr; is a wild pointer. • After the initialization it will became an ordinary pointer.

  6. dangling Pointers • It points to a destroyed variable. • It usually happens during dynamic memory allocation, when the object is destroyed but not free the pointer, it still pointing to the destroyed variable. • For Example: char *dp=malloc(…………) ; /*………code of the program………………………… …………code of the program………………………….*/ free(dp);// Now dp is a dengling pointer here. dp= NULL; // Now dp is not a dengling pointer, it is now a null pointer.

More Related