
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Is it safe to delete a void pointer in C/C++?
Void pointer is a pointer which is not associate with any data types. It points to some data location in storage means points to the address of variables. It is also called general purpose pointer.
It is not safe to delete a void pointer in C/C++ because delete needs to call the destructor of whatever object it's destroying, and it is impossible to do that if it doesn't know the type.
Here is a simple example of void pointer −
Example
#include<stdlib.h> int main() { int a = 7; float b = 7.6; void *p; p = &a; printf("Integer variable is = %d", *( (int*) p) ); p = &b; printf("\nFloat variable is = %f", *( (float*) p) ); return 0; }
Output
Integer variable is = 7 Float variable is = 7.600000
- Related Articles
- void pointer in C
- What is void pointer in C language?
- What is the size of void pointer in C/C++?
- Explain the concept of pointer to pointer and void pointer in C language?
- Differentiate the NULL pointer with Void pointer in C language
- Delete a Node from linked list without head pointer in C++
- Double Pointer (Pointer to Pointer) in C
- What is a smart pointer and when should I use it in C++?
- How to define pointer to pointer in C language?
- What is the size of a pointer in C/C++?
- A C/C++ Pointer Puzzle?
- What is Type safe in C#?
- What is pointer operator & in C++?
- What is Pointer operator * in C++?
- Pointer Arithmetic in C/C++

Advertisements