C++ Pointers

the pointer in c++ language is a available,it is also known as locator or indicator that points to an address of a value.

advantages of pointer:

  1. pointer reduces the code and improves the performance,it is used to retriving strings ,trees etc.and used with arrays,structures and functions.
  2. we can return multiple values from function using pointer 
  3. it makes you able to access any memory location in the computer's memory.

usage of pointer:

  1. dynamic memory allocation:in c language we can dynamically allocate memory using malloc() and calloc() functions.where pointer is used.
  2. Arrays,functions and structures:pointers in c language are widely used in arrays,functions and structures.it reduces the code and improves the performance. 

Declaring a pointer:

the pointer in c++ language can be declared using *

int * a;

char * c;

  poiter example:

#include<stdio.h>
using namespace std;
int main()
{
int number=30;
int * p;
p=&number;
cout<<"address of number variable is."<<&number<<endl;
cout<<"address of p variable is"<<p<<endl;
cout<<"value of p variable is"<<*p<<endl;
return 0;
}

Posted on by