A VARIABLE ISA CONTAINER THAT
HELPS TO STORE A VALUE LIKE WISE A
POINTER IS ALSO A CONTAINER
WHICH STORES THE ADDRESS OF
OTHER VARIABLE
3.
SYMBOLS IN POINTERS
•Indication operator /Dereference operator
(Access the values of that address)
Address operator
(determines the address of the
Variable )
4.
SAMPLE PROGRAMS :
OUTPUT:
Here the value “5” is printed bcoz the
value of k has been asked to print.
OUTPUT :
Here the value of k i.e “5” and the
address of the k are printed .
OUTPUT :
5.
USES OF POINTERS
Pointersprovide direct access to memory.
It provides a way to return more than one value to the function.
Reduces the storage space and complexity of the program.
Refers to the same space in memory from multiple locations so any change / update
will reflect anywhere.
Reduces the execution time of the program.
Provides an alternative way to access array elements.
It allows us to perform the dynamic memory allocation. And allows us to re-size it too.
Address of objects can be extracted using pointers.
THIS POINTER INC++
• The this pointer is an implicit parameter to all member functions. Therefore, inside a member
function, this may be used to refer to the invoking object.
• Friend functions do not have a this pointer, because friends are not members of a class. Only
member functions have a this pointer.
• The compiler supplies an implicit pointer along with the names of the functions
as ‘this’.
The ‘this’ pointer is passed as a hidden argument to all nonstatic member
function calls and is available as a local variable within the body of all nonstatic
functions. ‘this’ pointer is not available in static member functions as static
member functions can be called without any object (with class name).
For a class X, the type of this pointer is ‘X* ‘. Also, if a member function of X is
declared as const, then the type of this pointer is ‘const X *’
8.
The above codeis executed and the following output
is taken :
9.
REAL LIFE APPLICATIONEXAMPLE :
IF WE WANT TO MEET A PERSON AND WE HAVE ONLY HIS PHOTO . SO IT TAKES A LOT OF TIME TO
SEARCH HIM WITH THE HELP OF PHOTO ONLY , BUT IF THE ADDRESS OF THAT PERSON IS KNOWN IT
WOULD BE PRETTY GOOD AND THE JOB OF LOCATING AND MEETING HIM WOULD BE EASY PEASY