Pointers:

Pointers are the variables which store the address of other variables. Data type of pointer is same as that of the variable of which address it is storing.

datatype * pointerName = &variableName

Before exploring examples, we need to know about “&” and “*”.

Address Of Operator:

& is called the address of operator. It creates reference to a variable. When we put &-sign before a variable name, it gives us the address/reference of that variable in computer memory. The result we get is in hexadecimal form. As there is only one operand (variable), it is called unary operator.
int a = 10;
cout<< &a;
//Sample output: 0x61febc.

Dereference Operator:

"*" is called dereference operator. When we put * sign before a pointer variable, it dereferences it or we can say it gives us the data value at that address pointer is storing. struct is declared outside the main function.

int a = 10;
cout<<*(&a)<<endl;
//output: 10

Declaring a pointer:

int a=10;
int *ptr = &a; 

pointer.cpp
#include<iostream>
using namespace std;

int main(){
    int a = 10;
    int *ptr = &a;
    cout<<ptr<<endl; 
    cout<<*(ptr) 
    //We can also change values at address
    *ptr = 20;
    cout<<*(ptr)<<endl; //20 will be output
}

Pointers with Arrays:

Syntax for declaring array pointer is same as int or any other pointer.
int arr[3] = { 1,2,3 };
int *ptr = &arr;

Accessing array members using pointers:

pointer.cpp
#include<iostream>
using namespace std;

int main(){
    int arr[3] = { 1,2,3 };
    int *ptr = &arr; 
    cout<<*ptr; 
    cout<<*(ptr + 1); //output will be 2
    cout<<*(ptr + 2);//output will be 3
    return 0;
}

Pointer to Pointer:

Pointers are variables which store the address of another variable with the same data type. Pointers can also store the address of another pointer (variable). These are called pointer to pointer.
int a = 10;
int *ptr1 = &a;
int **ptr2 = &ptr1;

Note : You can declare variables of type void which store address of variable with any data type.