Difference Between *& and **& in C++

The below table illustrates the key differences between *& and **& in C++.

Feature

*& (Pointer to Reference)

**& (Pointer to Pointer Reference)

Definition

*& combines a pointer and a reference, allowing us to dereference a pointer and then immediately take a reference to the resulting value.

**& refers to a reference to a pointer to another pointer, allowing deep manipulation of pointer chains.

Syntax

int* ptr = & value;

int**& ref = ptrPtr;

Usage

It is used to modify the value at the pointer’s location indirectly through a reference in functions or complex data structures.

It is used to modify the address stored in a pointer or the pointer via itself, commonly used in dynamic and complex data manipulations.

Memory Access

It allows manipulation of the value pointed by the pointer, but not the address in the pointer.

It enables control over the address in a pointer and the value at that address, providing deeper manipulation capabilities.

Common Use

It is commonly used in scenarios where the value needs to be changed without modifying the pointer itself, like function calls where values need to be updated.

It is commonly used in scenarios requiring reassignment or reallocation of memory structures, such as modifying linked lists or dynamic arrays.

Effect on Pointed Data

It allows for direct modification of the data at the memory address pointed to, without affecting the pointer’s address.

It allows modification of the pointer’s address (i.e., where the pointer is pointing) and the data at the new address.





Difference Between *& and **& in C++

In C++, the *& (pointer to reference) and **&(pointer to pointer reference) symbols are used in the context of pointers and references for manipulating memory addresses and dealing with complex data structures. While they seem similar, they serve different purposes. In this article, we will learn the difference between *& and **& in C++.

Similar Reads

C++ Pointer to Reference( *& )

The *& symbol also called reference pointer is a combination of a pointer and a reference that is used to declare a pointer to a reference. The * symbol is used to declare a pointer, and the & symbol is used to get the address of a variable thus it creates a reference that point to the value stored by a pointer....

C++ Pointer to Pointer Reference (** & )

The **& symbol also called pointer to pointer reference(double pointer) is used to declare a pointer to a pointer. The ** symbol is used to declare a pointer to a pointer, and the & symbol is used to get the address of a pointer. It is mainly used for handling complex cases like multiple levels of indirection or managing dynamic memory allocation....

Difference Between *& and **& in C++

The below table illustrates the key differences between *& and **& in C++....