Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Presentation on
Ruturaj Nalawade
Sanjay Bidkar
Swapnil Sarwade
Under the Guidance of ,
Mrs . Ladda
POINTERS
INTRODUCTION
INTRODUCTION CONT.
E.g. :=
{
int i , *j;
i= 3;
j = &i;
cout<<The value of i is \t<<i<<endl;
cout<<The value of *j is \t<<*j;
}
Output : :
The value of i is 3
The value of *j is 3
INTRODUCTION CONT.
E.g. :=
{
int i , *j;
i= 3;
j = &i;
cout<<The value of i is \t<<i<<endl;
*j
cout<<The value of *j is \t<<*j;
}
Output : :
The value of i is 3
The value of *j is 3
Introduction - Cont.
How the *j gets the value of i ?
int i , *j ;
Variable
65524
65522
Names
Value
Memory
Address
Introduction - Cont.
How the *j gets the value of i ?
int i , *j ;
i=3;
Variable
Names
Value
Memory
Address
3
65524
65522
Introduction - Cont.
How the *j gets the value of i ?
int i , *j ;
i=3;
j=&i;
Variable
65524
65524
65522
Names
Value
Memory
Address
INTRODUCTION CONT.
C++
INTRODUCTION - CONT.
1. Constant Pointer
Declaration
::
INTRODUCTION - CONT.
2. Pointer to a Constant ::
data type const * pointer
3.
THIS POINTER
C++ uses keyword this to represent an
object that invokes a member function.
E.g. The function call A. max( ) will set the
pointer this to the address of the object A.
E.g. To access private variables inside a
member function
a=123;
or
this -> a = 123;
B *cptr;
B b;
D d;
cptr = & b;
we can also make cptr to point to the object
d as follows:
cptr = & d
Derived Class
Public:
a,b
Public / Private /
Protected :
Private /
Protected:
c,d
e,f,g,h
If cptr = & d;
cptr
a,b
. Casting
dptr -> show ( ) ;
( ( DC * ) bptr ) -> show ( ) ;
VIRTUAL FUNCTIONS
VIRTUAL FUNCTION
of some class.
They cannot be static members.
They are accessed by using object
pointers.
A virtual function can be friend of other
function.
A virtual function in a base class must be
defined , even though it may not be used.
RULES CONT.
6. We cannot have a virtual constructors,
but we can have virtual destructors.
RULES CONT.
8. The prototypes of the base class version
of a virtual function and all the derived
class versions must be identical.
RULES CONT.
POLYMORPHISM
POLYMORPHISM
Polymorphism is crucial feature of
Object Oriented Programming.
POLYMORPHISM - CONT.
Polymorphism
using C++.
POLYMORPHISM CONT.
Definition:
Polymorphism is the ability to create a
variable, a function or an object that has
more than one form.
EXAMPLE:
For example:
The + (plus) operator in C++:
4+5
<-- Integer addition
3.14 + 2.0 <-- Floating point addition
s1 + "bar" <-- String concatenation!
TYPES OF POLYMORPHISM
Polymorphism
Compile-time
Polymorphism
Function
Overloading
Operator
Overloading
Run-time
Polymorphism
Virtual
Function
TYPES OF POLYMORPHISM
In
In
BENEFITS OF
POLYMORPHISM
Simplicity:
REFERENCES :
Let us C++
by Yeshwant Kanetkar.
Internet.
THANK YOU !!