The following example let Understanding Pointer to a Pointer in C.
In order to provide multiple indirection, we can use pointer to pointer. Basically, a pointer refers to a location in memory where actual value is present. Similarly, a pointer to a pointer contains address of that address (pointer). Further indirection represent address at the next level.
For instance, in he following example, x contains a value of 300. While, y contains the address of x. Likewise, z and k contain the address of y and z respectively. Furthermore, we can change the value of x by using pointer to a pointer. Therefore, the expression ++***k increments the value of x by 1.
// Pointer to Pointer
#include <stdio.h>
int main()
{
int x;
int *y;
int **z;
int ***k;
x=300;
y=&x;
z=&y;
k=&z;
printf("\nx=%d", x);
printf("\ny=%x", y);
printf("\nz=%x", z);
printf("\nk=%x", k);
printf("\n*y=%d", *y);
printf("\n**z=%d", **z);
printf("\n***k=%d", ***k);
printf("\nUpdating Values using pointer...");
++***k;
printf("\nx=%d", x);
printf("\n*y=%d", *y);
printf("\n**z=%d", **z);
printf("\n***k=%d", ***k);
return 0;
}
Output
x=300
y=f01998ec
z=f01998f0
k=f01998f8
*y=300
**z=300
***k=300
Updating Values using pointer…
x=301
*y=301
**z=301
***k=301
Further Reading
50+ C Programming Interview Questions and Answers
C Program to Find Factorial of a Number
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Data Visualization
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- ES6
- Extended Reality
- Flutter and Dart
- Full Stack Development
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- Tkinter
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML