Technical Questions Based On C++
Technical Questions Based On C++
● Which operator is used to compare the values to find min and max?
The max function uses the ‘<’ operator and the min function uses the ‘>’ operator.
This minimum size is necessary to ensure that each instance of an empty class has a unique
address. If the size were zero, then two objects of the empty class could potentially have the
same address, which would violate the requirements of C++.
● In object oriented programming, by wrapping up characteristics and behavior into one unit, we
achieve
Encapsulation
● Which diagram provides a formal graphic notation for modelling objects, classes and their
relationships to one another?
An object diagram in the Unified Modeling Language (UML), is a diagram that shows a complete
or partial view of the structure of a modeled system at a specific time.
● The mechanism that binds code and data together and keeps them secure from outside world is
known as
Encapsulation is the mechanism that binds together code and data it manipulates, and keeps
both safe from outside interface and misuse.
• Function overloading
• Operator overloading
• Function overriding
• Virtual functions
The ultimate goal is to reduce both the learning curve and the defect rate.
Use common sense. If your overloaded operator makes life easier and safer for your users, do
it; otherwise don’t. This is the most important guideline. In fact it is, in a very real sense, the
only guideline; the rest are just special cases.
If you define arithmetic operators, maintain the usual arithmetic identities. For example, if
your class defines x + y and x – y, then x + y – y ought to return an object that is behaviorally
equivalent to x. The term behaviorally equivalent is defined in the bullet on x == y below, but
simply put, it means the two objects should ideally act like they have the same state. This
should be true even if you decide not to define an == operator for objects of your class.
You should provide arithmetic operators only when they make logical sense to users.
Subtracting two dates makes sense, logically returning the duration between those dates, so
you might want to allow date1 – date2 for objects of your Date class (provided you have a
reasonable class/type to represent the duration between two Date objects). However adding
two dates makes no sense: what does it mean to add July 4, 1776 to June 5, 1959? Similarly it
makes no sense to multiply or divide dates, so you should not define any of those operators.
● What is pointer?
Is a variable that stores the memory address of another variable as its value. A pointer variable
points to a data type (like int ) of the same type, and is created with the * operator.
● If class A inherits from more than one class, ie. A inherits from B1, B2, ...is called
If class A inherits from more than one class, ie. A inherits from B1, B2, …, Bn, we speak of
multiple inheritance.
● If class A inherits from class B, then B is called _______ of A. A is called ________ of B.
If class A inherits from class B, then B is called superclass of A. A is called subclass of B.