A variable that contains the address of another variable or address of a memory location is called a pointer. A pointer is also called a pointer variable. A pointer variable can store address of other variables.
In C++
language we know that all the variables should be declared before they are used, pointer variables should be declared before they are used.
Q.)W.A.P to initialize pointer to variable.
// C++ program to illustrate Pointers
#include
using namespace std;
void geeks()
{
int var = 20;
// declare pointer variable
int* ptr;
// note that data type of ptr and var must be same
ptr = & var;
// assign the address of a variable to a pointer
cout << "Value at ptr = " << ptr << "\n";
cout << "Value at var = " << var << "\n";
cout << "Value at *ptr = " << *ptr << "\n";
}
// Driver program
int main()
{
geeks();
return 0;
}