Pointer in c++

It is a special type of variable which is used to store the address of another varriable.

It can store the address of same data type means an integer pointer can store the address of integer variable, character pointer can store the address of character variable and so on.

If we add asterisk (*) symbol with any variable at the time of declaring variable then this variable is called pointer variable.

We use ampersand symbol to get the address of variable.

asterisk (*) symbol is used o get the value at address which is hold by pointer.

Syntax;

int a;
int *p;
  • Here a is normal variable.
  • p is a pointer variable because it is associated with (*) asterisk symbol.

Example:

#include< iostream.h >
void main()
{
int a=10;
int *p;
p=&a;
cout <<" value of a = "<< a;
cout <<" address of a = "<< &a;
cout <<" value of p = "<< p;
cout << " address of p = "<< &p;
cout << " value of *p = " << *p;
}

Output:

value of a = 10
address of a = 8284
value of p = 8384
address of p =8288
value of *p = 10

output Explaination

Assume that the address of variable a is 8284 and address of variable p is 8388, it may be diffrent in your system.