
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
void pointer in C
The void pointer in C is a pointer which is not associated with any data types. It points to some data location in the storage means points to the address of variables. It is also called general purpose pointer. In C, malloc() and calloc() functions return void * or generic pointers.
It has some limitations −
1) Pointer arithmetic is not possible with void pointer due to its concrete size.
2) It can’t be used as dereferenced.
Algorithm
Begin Declare a of the integer datatype. Initialize a = 7. Declare b of the float datatype. Initialize b = 7.6. Declare a pointer p as void. Initialize p pointer to a. Print “Integer variable is”. Print the value of a using pointer p. Initialize p pointer to b. Print “Float variable is”. Print the value of b using pointer p End.
Here is a simple example −
Example Code
#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
- Differentiate the NULL pointer with Void pointer in C language
- What is void pointer in C language?
- Explain the concept of pointer to pointer and void pointer in C language?
- What is the size of void pointer in C/C++?
- Is it safe to delete a void pointer in C/C++?
- Double Pointer (Pointer to Pointer) in C
- Return from void functions in C++
- How does “void *” differ in C and C++?
- Pointer Arithmetic in C/C++
- How to define pointer to pointer in C language?
- NULL pointer in C
- Function Pointer in C
- Dangling, Void, Null and Wild Pointers in C/C++
- Explain the concept of Array of Pointer and Pointer to Pointer in C programming
- Dangling, Void, Null and Wild Pointers in C++

Advertisements