Home >>C++ Tutorial >C++ Pointers

C++ Pointers

C++ Pointers

The pointers in C++ programming language is basically a variable that is also called as locater or installer that generally point towards the address of a provided value.

Advantages of Pointer

There are many advantages of the pointers, some of them are as follows:

  • Pointers in C++ are known to enhance the performance and reduce the code. It is also used in retrieving trees, strings, etc.
  • Multiple values can be returned from a function by the use of pointers.
  • Any memory location in the computer’s memory can be accessed by the user with the help of pointers.

Uses of Pointers

Here are the uses of the pointers in the C++ programming language:

  • Dynamic memory allocation
  • Arrays, Functions and Structures

Pointers are used widely in arrays, functions and structures in C++ as they are known to enhance the performance and reduce the code.

Symbols used in Pointers

Symbol Name Description
&(ampersand sign) Address operator It is used to determine the address of a variable.
*(asterisk sign) Indirection operator It is used to access the value of an address.

Declaring a Pointer

By using the * asterisk symbol, a pointer is declared in the C++.

Syntax

int *   a; //pointer to int    
char *  c; //pointer to char    

Here are the examples of the pointers that will help you understand the topic better:

#include <iostream>  
using namespace std;  
int main()  
{  
int num=10;    
int *p;      
p= & num;  
cout<<"Print Address of num variable : "<<&num<<endl;    
cout<<"Print Address of p variable :"<<p<<endl;    
cout<<"Print the Value of p variable :"<<*p<<endl;
return 0;  
}  
Output :
Print Address of num variable : 0x7fff91e40504
Print Address of p variable :0x7fff91e40504
Print the Value of p variable :10