C++ Pointers

What is Pointers ?

A Pointer is a variable that is used to store a memory address.The reference operator is used to access the memory address of a variable and store in a pointer.


Pointer Declaration 

The method of declaring pointer is same as declaring a simple variable. An Asterisk '*' is used in the declaration that indicate that  the variable is pointer variable.

Syntax
DataType *variable_name;
int int *p;

Example 

#include <iostream>
#include <string>
using namespace std;
int main() {
int *p; // declare pointer variable
int ptr=50;
p = &ptr;
cout<<"Value of P = " <<ptr; //output value
cout<<endl;
cout<<"Address of P = " <<&p; //output memory address of value ptr
}

Output:



<< C++ Strings        --        C++ Date & Time >>