In C++, a pointer is a variable that contains the address of another variable rather than store the value directly. Just the same way as a variable of type int is used to contain an integer value, A pointer varibale is one that is used to contain a memory address.
Declaring a Pointer
Type *pointer_variable_name = null; //initializing value
Declaring a pointer to an integer would be:
Program to determining the addresses of an int and a double
Using poiters to stor addresses
Assume a variabe declaration of the types you already know :
//declaraing a variable Type variable_name = initial_value;
To store the address of a variable in a pointer, you would declare a pointer to the same type and initialized the pointer to the variable’s address using the refrence operator (&):
//declaring a pointer to the same type and iniatializing to address: Type* pointer = &variable;
Program to demnostrate the declaration and initialization of a pointer
Program that demostrate pointer reassignment to another variable
What is the sizeOf() of a Pointer ?
It returns the no. of bytes required to store, The sizeOf() is a pointer is hence dependent on the compiler and the operating system the program has been compiled for.
Program to demonstrate that pointers to different types have the same sizes –