Professional Documents
Culture Documents
3
WHAT IS POINTER
• Pointers are symbolic representation of addresses. They enable programs to simulate call-by-reference as well as to create
and manipulate dynamic data structures. It’s general declaration in C/C++ has the format:
• Syntax:
• datatype *var_name;
• int *ptr; //ptr can point to an address which holds int data
• The reason we associate data type to a pointer is that it knows how many bytes the data is stored in. When we increment a
pointer, we increase the pointer by the size of data type to which it points
4
SAMPLE PROGRAM IN C++
6
PROGRAM
18
WHEN THIS POINTER IS USED?
• When local variable’s name is same as member’s name
• Method Chaining
• Returning object
19
WHEN THIS POINTER IS USED?
• When local variable’s name is same as member’s name
24
POINTER TO OBJECT
29
VIRTUAL FUNCTIONS
By default early binding happens in C++. Late binding (discussed below) is achieved with the help of virtual keyword)
Virtual means existing in appearance but not in reality. When virtual functions are used, a program that appears to be calling a
function of one class may in reality be calling a function of a different class.
• Virtual functions ensure that the correct function is called for an object, regardless of the type of reference (or pointer) used
for function call.
• They are mainly used to achieve Runtime polymorphism
• Functions are declared with a virtual keyword in base class.
• The resolving of function call is done at Run-time.
30
DEFAULT- EARLY BINDING
35
APPLICATIONS OF THIS POINTER
36
REFERENCES
• Reference Website
[1] https://www.geeksforgeeks.org/pointers-c-examples/
[2] https://techdifferences.com/difference-between-static-and-dynamic-binding.html
[3] https://www.geeksforgeeks.org/copy-constructor-argument-const/
[4] https://www.softwaretestinghelp.com/runtime-polymorphism-in-cpp/
37
THANK YOU
For queries
Email: CST157_2019@gmail.com