
- 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
Explain the concept of pointer to pointer and void pointer in C language?
Double pointer or pointer to pointer is a variable that holds the address of another pointer.
Following is the declaration for a pointer to a pointer −
datatype ** pointer_name;
For example, int **p; p is a pointer to pointer
Initialization − ‘&’ is used for initialization.
For example,
int a = 10; int *p; int **q; p = &a;
Accessing − Indirection operator (*) is used for accessing.
Example
Following is the C program for the pointer to pointer −
#include<stdio.h> main ( ){ int A = 10; int *p; int **q; p = &A; q = &p; printf("A =%d",A); printf("A value of pointer = %d", *p); printf("A value of double pointer = %d", **q); }
Output
When the above program is executed, it produces the following result −
A=10 A value of pointer = 10 A value of double pointer = 10
Void pointers
It is a type of pointer that can hold the address of any datatype variable (or) can point to any datatype variable.
Following is the declaration for the void pointer −
void *pointername;
For example, void *vp;
Accessing − Type cast operator is for accessing the value of a variable through its pointer.
The syntax is as follows −
* ( (type cast) void pointer)
For example,
int i=10; void *vp; vp = &i; printf ("%d", * ((int*) vp)); type cast
Example
Following is the C program for the void pointer −
#include<stdio.h> main ( ){ int i =10; float f = 5.34; void *vp; clrscr ( ); vp = &i; printf ("i = %d", * ((int*)vp)); vp = &f; printf ( "f = %f", * ((float*) vp)); getch ( ); }
Output
When the above program is executed, it produces the following result −
i = 10 f = 5.34
- Related Articles
- Explain the concept of Array of Pointer and Pointer to Pointer in C programming
- Differentiate the NULL pointer with Void pointer in C language
- Explain the concept of pointer accessing in C language
- What is void pointer in C language?
- void pointer in C
- How to define pointer to pointer in C language?
- Explain the Union to pointer in C language
- Double Pointer (Pointer to Pointer) in C
- What is the size of void pointer in C/C++?
- Explain the dynamic memory allocation of pointer to structure in C language
- Explain reference and pointer in C programming?
- Is it safe to delete a void pointer in C/C++?
- C program to display relation between pointer to pointer
- How to access the pointer to structure in C language?
- NULL pointer in C
