• Pointers are symbolic representation of addresses and it enables a program to simulate call-by-reference as well as to create and manipulate dynamic data structures.
  • It defines a pointer variable and its general declaration in C/C++ has the format.
  • Using unary operator (&) assigning the address of a variable to a pointer which returns the address of that variable.
  • Using unary operator (*) accessing the value stored in the address which returns the value of the variable located at the address specified by its operand.
  • When we increment a pointer, we increase the pointer by the size of data type to which it points, this is the reason data type to a pointer is knows how many bytes the data is stored inside.

Syntax

datatype *var_name; 
int *ptr;

Sample Code

#include <iostream>
using namespace std;
int main() {
int x = 27;
int *ip;
ip = &x;
cout << "Value of x is : ";
cout << x << endl;
cout << "Value of ip is : ";
cout << ip<< endl;
cout << "Value of *ip is : ";
cout << *ip << endl;
return 0;
}

Output

Categorized in: