Object Oriented Programming - C++: Chapter 4: Pointers and Runtime Polymorphism: Anna University Part A Two Marks Important Questions and Answers
Object Oriented Programming – C++
Chapter 4: Pointers and Runtime
Polymorphism
Two Marks
Questions with Answers
1. Differentiate
constant pointer and a pointer to a constant with an example.
Answer: A constant pointer is a pointer that can not
change the address it is holding. A pointer to a constant is a pointer using
which one can not change the value of variable it points to.
2. What
is the use of void pointer ?
Answer:
The void pointer is a special type of pointer that can be used to point to the
objects of any data type. It is also known as generic pointer.
The
void pointer is declared like normal pointer declaration, using the keyword
void.
For
example:
void
*ptr;
3. What
is pointer arithmetic ?
Answer:
Pointer arithmetic is a set of arithmetic operations by which we can ‒ 1. use
++ or ‒‒
operators
using pointers. 2. We can add or subtract an integer to a pointer variable.
4. What
are the two operators used in pointers ?
Answer:
The two operators used in pointers are* and &. The* denotes the value at
particular location while the & denotes the address of variable.
5. How
are virtual functions declared in C++?
Answer:
Virtual function is a member function that is declared within a base class and
redefined by a derived class. The virtual keyword is preceded to the function
name. This virtual function can be redefined in the derived class. The virtual
function within the base class defined the form of the interface to that
function. Each redefinition of the virtual function by a derived class indicate
some different task related to derived class.
6. When
do we make a virtual function "pure" ?
OR
Define
pure virtual function and mention its usage.
Answer:
The pure virtual function is used in abstract class. When we want to override
the definition of some particular function in the derived class then we
normally declare that function as pure virtual function in the base class.
7. What
is the difference between compile time and run time polymorphism ?
Answer:
Compile time polymorphism: The
linking between method call and method definition takes place at compile time.
Compiler knows the exact memory address of the function definition. The
advantage of this approach is that the execution of the code becomes fast.
For
example ‒ Function oveloading
Run time polymorphism:
The linking between method call and method definition takes place at run time.
The advantage of this approach is that size of compiled code get reduced.
For
example ‒ Virtual functions
8. What
is function overriding?
Answer:
The function overriding means redefining of a function in a derived class.
9. Give
the difference between the function overloading and function overriding.
Answer:
In both the function overloading and function overriding the function names
remain the same. But in function overloading the two functions of same name can
have varying number of arguments. They can have different return types. But in
function overriding the signature of the function must be the same. Only the
body of the function differs.
10. Compare
overloading and overriding.
Answer:

Overloading
1.
In function overloading different number of parameters can be passed to the
function.
2.
The overloading function may have different return type.
3.
This method allows defining multiple member functions with same name but
different signature.
Overriding
1.
In function overriding the number of parameters that are passed to the function
must be the same.
2.
The return type of base and derived member function must be the same.
3.
Overriding is a method that allows a class to redefine the behaviour of member
functions which the derived class inherits from the base class.
11. Define
the virtual functions.
Answer:
A virtual function is a member function that is declared within a base class
and redefined by a derived class. For the virtual function the virtual keyword
is preceded to the function name.
Object Oriented Programming: Chapter 4: Pointers and Runtime Polymorphism : Tag: Oops, Computer Programming : C++ Object Oriented Programming - Pointers and Runtime Polymorphism: Two Marks Important Questions and Answers
Object Oriented Programming (OOPs)
CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
Applied Physics (CSIE) II
PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Digital Principles and Computer Organization
CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electrical and Electronics Engineering
EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Object Oriented Programming (OOPs)
CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Re-Engineering for Innovation
ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Object Oriented Programming (OOPs) - Laboratory
CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation