You are on page 1of 3

Object Oriented Programming

Assignment #2
Part 1: Theory
Short Question Answers
(2)
Constant Pointers: This type of pointers are the one which
cannot change address they are pointing to. This means that
suppose there is a pointer which points to a variable (or stores
the address of that variable). Now if we try to point the pointer
to some other variable (or try to make the pointer store address
of some other variable), then constant pointers are incapable of
this.
Declaration: int *const ptr
Pointer to Constant: These type of pointers are the one which
cannot change the value they are pointing to. This means they
cannot change the value of the variable whose address they
are holding.
Declaration: const int *ptr
(3)
If you are writing a function that accepts an argument and you want to
make sure the function cannot change the value of the argument, what
do you do?
(Answer) If the argument is passed by value, nothing needs to
be done. The function cannot access the argument. If the
argument is passed by reference, the parameter should be
defined with the const key word.
(4)
Is an array passed to a function by value or by reference? Explain
your answer
(Answer) Yes, array can pass to a function by value or by reference.
Call By value
In call by value, original value is not modified.
In this, value being passed to the function is locally stored by the
function parameter in stack memory location. If you change the value
of function parameter, it is changed for the current location only. It
will not change the value of variable inside the caller method such as
main().
(5)
Is it possible to have more than one constructor? Is it possible to have
more than one destructor?
(Answer) Yes, it is possible to have more than one constructor which
is called constructor overloading.
No, it is not possible to have more than one destructor and destructors
has no parameters.
(6)
If a class object is dynamically allocated in memory, does its
constructor execute? If so, when?
(Answer) Yes, the constructor executes when an object is invoked in
memory.
(7)
Difference between encapsulation and abstraction?
(Answer) Encapsulation
Binding (or wrapping) code and
data together into a single unit is known as
encapsulation. For example: capsule, it is wrapped
with different medicines.
Abstraction

Hiding internal details and showing


functionality is known as abstraction. For example:
phone call, we don't know the internal processing.

In C++, we use abstract class and interface to achieve


abstraction. (www.javatpoint.com)

(8)

What advantages does a vector offer over an array?

(Answer) .1

You might also like