Pointer is C++ Language
Pointer is most powerful tool of C++. It is a variable to store the address of variable. Every variable stored in the unique memory location in computer. The pointer is the different beast because it hold the memory addresses as its value and has an ability to point to certain value within a memory location. A pointer is one of the most important concepts in C and C++ language. Pointer is a variable that stores a memory address.
Use of Pointer Operators ( & and *):
There are two main operators which we can use as pointers operators:
1. & : Address of the variable operator
2. * : value at that address
Lets explain all these pointer operators with the help of a C++ program:
#include<iostream>
using namespace std;
int main()
{
int x = 20;
int *y; // pointer declaration
y = &x; // pointer variable y assigned with address of x as &x contain address of x
cout<<"Value of y is : "<< y<<endl;;
cout<<"Value of *y is : "<< *y<<endl;
cout<<"Value of &y is : "<< &y<<endl;
cout<<"Value of x is : "<< y<<endl;
cout<<"Value of &x is : "<< &x<<endl;
return 0;
}
This program output is tested on www.jdoodle.com
Output:
Value of y is : 0x7ffdddc195fc // address of x
Value of *y is : 20 // Value of *y is equal to x
Value of &y is : 0x7ffdddc19600 // Address of y
Value of x is : 20 // value of x
Value of &x is : 0x7ffdddc195fc // Address of x
Thanks
Mukesh Rajput
Post A Comment:
0 comments: