A pointer is a variable that stores the address of another variable in c++.
The address of the variable you’re working with is assigned to the pointer variable that points to the same data type (such as an int or string).
The pointer is a variable, it is also known as a locator or indicator that points to an address of a value.
Advantage of pointer :
Pointer reduces the code and improves the performance, it is used to retrieve strings, trees etc, and used with arrays, structures, and functions.
We can return multiple values from a function using a pointer.
It makes you able to access any memory location in the computer’s memory.
Also Read This :- structure in c++
Symbols used in pointer :
Symbol | Name | Description |
---|---|---|
& | Address operator | Determine the address of a variable. |
* | Indirection operator | Access the value of an address. |
Declaration of Pointer in c++ :
datatype *var_name; int *ptr;
Example of Pointer in c++ :
#include<iostream> #include<conio.h> using namespace std; int main() {  int number=30;  int *p;  p=&number;//stores the address of number variable    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; }
output
Address of number variable is:0x61ff08 Address of p variable is:0x61ff08 Value of p variable is:30
A friend function post is a good post and easy to understand
And I hope the next post is also easy to understand.