CPP005 : C++ Interview - Part5 | Pointer | Null Pointer | Void Pointer | Pointer to Constant

Publicado el: 30 mayo 2023
en el canal de: The Digital Folks
142
6

A pointer is a variable that stores the memory address of another variable as its value. A pointer variable points to a data type (like int ) of the same type, and is created with the * operator.

C – Pointer to Pointer (Double Pointer)
The pointer to a pointer in C is used when we want to store the address of another pointer. The first pointer is used to store the address of the variable. And the second pointer is used to store the address of the first pointer. That is why they are also known as double-pointers. We can use a pointer to a pointer to change the values of normal pointers or create a variable-sized 2-D array. A double pointer occupies the same amount of space in the memory stack as a normal pointer.

C++ Null Pointers

It is always a good practice to assign the pointer NULL to a pointer variable in case you do not have exact address to be assigned. This is done at the time of variable declaration. A pointer that is assigned NULL is called a null pointer.

void pointer in C / C++

A void pointer is a pointer that has no associated data type with it. A void pointer can hold address of any type and can be typecasted to any type.

Pointers vs References in C++

References: A reference variable is an alias, that is, another name for an already existing variable. A reference, like a pointer, is also implemented by storing the address of an object.

A reference can be thought of as a constant pointer (not to be confused with a pointer to a constant value!) with automatic indirection, i.e., the compiler will apply the * operator for you.

Pointer to Constant

As the name itself indicates that the value of the variable to which the pointer is pointing is constant in other words a pointer through which one cannot change the value of variable it points is known as a 'pointer to constant'.

Constant Pointer
In constant pointers, the pointer points to a fixed memory location, and the value at that location can be changed because it is a variable, but the pointer will always point to the same location because it is made constant here.


================ content of this video ================


0:00 Intro
0:55 Pointer Definition
3:25 Calculate size of variable using pointer
5:38 Why Pointer ?
8:25 Double Pointer
9:23 NULL pointer
11:15 void pointer
13:41 Reference
16:55 Pointer to Constant
17:44 Constant Pointer


En esta página del sitio puede ver el video en línea CPP005 : C++ Interview - Part5 | Pointer | Null Pointer | Void Pointer | Pointer to Constant de Duración hora minuto segunda en buena calidad , que subió el usuario The Digital Folks 30 mayo 2023, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 142 veces y le gustó 6 a los espectadores. Disfruta viendo!