Pointers in C++
Pointers is also a data type which is used the address int type . C++ is very easy to Learn and Fun , Some C++ tasks are to performed more easily with pointers and other C++ tasks , such as dynamic memory allocation , cannot be perform without them .
As we know that every variable is a memory location and every memory location has it's address define which can not be accessed using ampersand (&) operator which denotes an address in memory consider the following which will pint the addresses of the variable defined --
Syntax :
datatpe*var_name ( Variable name)
int* ptr // ptr points to the address which holds the int data .
Example :
Output :
Address of int Data : a0x61ff08
Value of Int Data : 10
A pointer is a variable whose value is the address of another variable . Like any Variable or constant , you must declare a pointer before you can work with it .
when you Create a variable in your C++ program , It is assigned some space the computer memory . The value of this variable is stored in the assigned location . to know the location in the computer memory where the data is stored in C++ provides the &(Reference) operator The operator returns the address that a variable occupies.
The deference operator(*) helps us to get the value which is stored in memory address
For Example :
If you have a variable given the name num , stored in the address 0x234 and storing the value 28 .
The reference operator (&) will return 0x234
The Deference operator (*) will return 5 .
Pointers can be used to pass of arrays and strings to function more efficiently . Pointers save the memory . Pointers reduce the length and Complexity of the Program . Pointers make possible to return more than one value from the function .
Pointers in C++ Video : Click Here
Please ! write comment if you find anything incorrect in this website .
This article is contributed by Mohd abuzar . If you want to like code with abuzar or want to contribute with us so mail at - abuzar.abuzar.mohd325@gmail.com
0 Comments
Do not Comment and any spam text