0% found this document useful (0 votes)
17 views4 pages

Technical Questions Based On C++

This document contains technical questions and answers related to C++. It discusses topics like function headers, min/max functions, object classes, access specifiers, encapsulation, inheritance, polymorphism and more.

Uploaded by

Shail Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Technical Questions Based On C++

This document contains technical questions and answers related to C++. It discusses topics like function headers, min/max functions, object classes, access specifiers, encapsulation, inheritance, polymorphism and more.

Uploaded by

Shail Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Technical Questions based on C++

● Which keyword is used to declare the min and max functions?


Algorithm header file contain the supporting files needed for the execution of these functions.

● What kind of functions are min and max in C++?


The min/max functions are type specific but they will not force everything to be converted
to/from floating point. The functions that will force everything to be converted to/from floating
point are fmin/fmax.

● How many parameters are needed for min/max function?


The “minmax” function can take the following:
1 parameter: An initializer_list object.
2 parameters: Values to compare.
2 parameters: An initializer_list object. And comparison function
3 parameters: Values to compare. And comparison function

● Which function is used to return the minimum element in the range?


The min_element is used to compare the range of elements and it can find out the minimum
element.

● 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.

● What is a size of empty class in c++?


In C++, an empty class is a class that does not contain any data members or member functions.
The size of an empty class is not zero, because every object in C++ must have a distinct
address. However, the size of an empty class is guaranteed to be at least 1 byte.

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 c++ object of the class is also called?


In C++, an object is an instance of a class. A class is a blueprint or a template for creating
objects, and an object is a specific instance of that class. Objects encapsulate data and the
functions that operate on that data.

● ________ is a default access specifier for members of class in C++.


Private

● ________ is a default access specifier for members of structures in C++.


In C++, the default access specifier for members of a structure is `public`. This means that
members of a structure are accessible from outside the structure without any restrictions by
default. If you don’t explicitly specify an access specifier for the members of a structure, they
are treated as public members.

● 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.

● A Class can have how many destructor?


In a class, we can only have one destructor. In a class followed by a class name, there can only
be one destructor with no parameters and no return type.

● The parameter list in function overloading must differ by?


Number of argument

● Data members are also called?


Attribute

● In how many ways is polymorphism achieved in C++?


Compile time –
The implementation of compile-time polymorphism is achieved in two ways:

• Function overloading
• Operator overloading

The implementation of run time polymorphism can be achieved in two ways:

• Function overriding
• Virtual functions

● The Object is not declared for which class?


● The constructor without parameter is called?
A constructor that takes no parameters is called a parameterless constructor. Parameterless
constructors are invoked whenever an object is instantiated by using the new operator and no
arguments are provided to new .

● The static member variable is initialized to?


In C++ or similar programming languages, a static member variable is initialized to zero by
default if you don’t explicitly provide an initialization value. This initialization occurs at the start
of the program before any instances of the class are created or any static member functions are
called.

● A __________ is a special method used to initialize the instance variable of a class.


Constructor
● Member of a class specified as _______ are accessible only to method of the class.
Private

● The goal of operator overloading is __________.


By overloading standard operators on a class, you can exploit the intuition of the users of that
class. This lets users program in the language of the problem domain rather than in the
language of the machine.

The ultimate goal is to reduce both the learning curve and the defect rate.

Few guidelines / rules of thumb to perform operator overloading

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 features make C++ so powerful?


C++ is an advanced language that supports a wide range of programming techniques, like
procedural, object-oriented, functional, etc. Abstraction, Encapsulation, Inheritance, and
Polymorphism are the four main pillars of C++ that also make it more powerful and flexible.

● Local Variables can be access?


It can only access these variables in that specific function where they are declared or passed in
as an argument.

● In C++ every statement end with?


A semi-colon

● 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.

● ________ is the mechanism which allows a class A to inherit properties of a class B.


Inheritance is the mechanism which allows a class A to inherit properties of a class B. We say ``A
inherits from B’’. Objects of class A thus have access to attributes and methods of class B
Without the need to redefine them.

● Who is father of C++ Language?


Bjarne Stroustrup, the designer and original implementer of the programming language C++, a
programming language used worldwide. Dr. Stroustrup began developing C++ in 1979, which
first made its public appearance in 1985.

You might also like