Académique Documents
Professionnel Documents
Culture Documents
1. Which of the following is not one of the sizes of the floating point types?
a) short float
b) float
c) long double
d) double
Answer: a
Explanation: Floating point types occur in only three sizes-float, long double and double.
2. Which of the following is a valid floating-point literal?
a) f287.333
b) F287.333
c) 287.e2
d) 287.3.e2
Answer: c
Explanation: To make a floating point literal, we should attach a suffix of ‘f’ or ‘F’ and there should not be
any blank space.
a) -3.4E+38 to +3.4E+38
b) -3.4E+38 to +3.4E+34
c) -3.4E+38 to +3.4E+36
d) -3.4E+38 to +3.4E+32
Answer: a
Explanation: This is the defined range of floating type number sin C++. Also range for +ve and -ve side
should be same so the answer is -3.4E+38 to +3.4E+38.
4. Which of three sizes of floating point types should be used when extended precision is required?
a) float
b) double
c) long double
d) extended float
Answer: c
Explanation: Float for single precision, double for double precision and long double for extended precision
5. Which is used to indicate single precision value?
a) F or f
b) L or l
c) Either F or for L or l
d) Neither F or for L or l
Answer: a
Explanation: Either F or f can be used to indicate single precision values.
int (*fp)(char*)
a) pointer to a pointer
b) pointer to an array of chars
c) pointer to function taking a char* argument and returns an int
d) function taking a char* argument and returning a pointer to int
Answer: c
Explanation: The (*fn) represents a pointer to a function and char* as arguments and returning int from the
function. So according to that, the above syntax represents a pointer to a function taking a char* as an
argument and returning int.
7. The operator used for dereferencing or indirection is ____
a) *
b) &
c) ->
d) –>>
Answer: a
Explanation: * is used as dereferencing operator, used to read value stored at the pointed address.
string* x, y;
Answer: a
Explanation: * is to be grouped with the variables, not the data types.
Answer: d
Explanation: A pointer can be in only 3 states a,b and c.
a) int *ip;
b) string s, *sp = 0;
c) int i; double* dp = &i;
d) int *pi = 0;
Answer: c
Explanation: dp is initialized int value of i.
a) int array[10];
b) int array;
c) array{10};
d) array array[10];
Answer: a
Explanation: Because array variable and values need to be declared after the datatype only.
12. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined
Answer: b
Explanation: Because the first element always starts at 0. So it is on 8 position.
Answer: a
Explanation: Correct definition of an array is An array is a series of elements of the same type in contiguous
memory locations.
14. Which of the following accesses the seventh element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;
Answer: a
Explanation: The array location starts from zero, So it can accessed by array[6].
15. Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;
Answer: d
Explanation: To get the address of ith index of an array, we use following syntax (arr + i). So as we need
address of first index we will use (arr + 0) equivalent to arr.
UNIT TWO: Operator Overloading and Inheritance
a) Array subscripting
b) Function call
c) Addition and subtraction
d) Type cast
Answer: d
Explanation: There are many right to left associativity operators in C++, which means they are evaluation is
done from right to left. Type Cast is one of them. Here is a link of associativity of operators:
a) postfix
b) unary
c) shift
d) equality
Answer: a
Explanation: The operator which is having highest precedence is postfix and lowest is equality.
a) conditional
b) relational
c) casting operator
d) none of the mentioned
Answer: a
Explanation: In this operator, if the condition is true means, it will return the first operator, otherwise second
operator.
Answer: a
Explanation: Because the dynamic_cast operator is used to convert from base class to derived class.
a) type
b) number of arguments
c) type & number of arguments
d) none of the mentioned
Answer: c
Explanation: Both type and number of arguments permits function overloading in C++, like
int func(int);
float func(float, float)
Here both type and number of arguments are different.
a) return function
b) caller
c) called function
d) none of the mentioned
View Answer
Answer: a
Explanation: While overloading the return function, it will rise a error, So we can’t overload the return
function.
a) operator overloading
b) constructor overloading
c) destructor overloading
d) none of the mentioned
Answer: b
Explanation: In constructor overloading, we will be using the same options availed in function overloading.
8. Overloaded functions are
Answer: c
Explanation: This is the definition of function overloading i.e. function having same name but different
number of parameters and types.
a) The values of those variables are passed to the function so that it can manipulate them
b) The location of variable in memory is passed to the function so that it can use the same memory
area for its processing
c) The function declaration should contain ampersand (& in its type declaration)
d) All of the mentioned
Answer: b
Explanation: In pass by reference, we can use the function to access the variable and it can modify it.
Therefore we are using pass by reference.
10. What should be passed in parameters when function does not require any parameters?
a) void
b) blank space
c) both void & blank space
d) none of the mentioned
Answer: b
Explanation: When we does not want to pass any argument to a function then we leave the parameters blank
i.e. func() – function without any parameter.
a) Changes to parameter values within the function also affect the original arguments
b) There is need to copy parameter values (i.e. less memory used)
c) There is no need to call constructors for parameters (i.e. faster)
d) All of the mentioned
Answer: d
Explanation: All above mentioned are advantages and properties of call by reference.
a) Dot
b) Comma
c) Dollar
d) None of the mentioned
Answer: b
Explanation: For using multiple inheritance, simply specify each base class (just like in single inheritance),
separated by a comma.
a) Dynamic binding
b) Polymorphism
c) Both Dynamic binding & Polymorphism
d) None of the mentioned
Answer: c
Explanation: The benefit of dynamic binding and polymorphism is that they help making the code easier to
extend but by multiple inheritance it makes harder to track.
15. What are the things are inherited from the base class?
Answer: a
Explanation: It is actually the ability for a message / data to be processed in more than one form. The word
polymorphism indicates many-forms. So if a single entity takes more than one form, it is known as
polymorphism.
2. What do you call the languages that support classes but not polymorphism?
Answer: c
Explanation: The languages which support classes but doesn’t support polymorphism, are known as object-
based languages. Polymorphism is such an important feature, that is a language doesn’t support this feature,
it can’t be called as a OOP language.
3. Which among the following is the language which supports classes but not polymorphism?
a) SmallTalk
b) Java
c) C++
d) Ada
Answer: d
Explanation: Ada is the language which supports the concept of classes but doesn’t support the
polymorphism feature. It is an object-based programming language. Note that it’s not an OOP language.
4. If same message is passed to objects of several different classes and all of those can respond in a
different way, what is this feature called?
a) Inheritance
b) Overloading
c) Polymorphism
d) Overriding
Answer: c
Explanation: The feature defined in question defines polymorphism feature. Here the different objects are
capable of responding to the same message in different ways, hence polymorphism.
a) Inline function
b) Virtual function
c) Undefined functions
d) Class member functions
Answer: b
Explanation: Only virtual functions among these can show polymorphism. Class member functions can
show polymorphism too but we should be sure that the same function is being overloaded or is a function of
abstract class or something like this, since we are not sure about all these, we can’t say whether it can show
polymorphism or not.
6. In case of using abstract class or function overloading, which function is supposed to be called first?
a) Local function
b) Function with highest priority in compiler
c) Global function
d) Function with lowest priority because it might have been halted since long time, because of low
priority
Answer: b
Explanation: Function with highest priority is called. Here, it’s not about the thread scheduling in CPU, but
it focuses on whether the function in local scope is present or not, or if scope resolution is used in some way,
or if the function matches the argument signature. So all these things define which function has the highest
priority to be called in runtime. Local function could be one of the answer but we can’t say if someone have
used pointer to another function or same function name.
Answer: a
Explanation: Static member functions are not property of any object. Hence it can’t be considered for
overloading/overriding. For polymorphism, function must be property of object, not only of class.
a) Overloading ||
b) Overloading +=
c) Overloading <<
d) Overloading &&
Answer: c
Explanation: Only insertion operator can be overloaded among all the given options. And the polymorphism
can be illustrated here only if any of these is applicable of being overloaded. Overloading is type of
polymorphism.
a) True
b) False
Answer: a
Explanation: It is possible to implement polymorphism in C language, even though it doesn’t support class.
We can use structures and then declare pointers which in turn points to some function. In this way we
simulate the functions like member functions but not exactly member function. Now we can overload these
functions, hence implementing polymorphism in C language.
10. Which problem may arise if we use abstract class functions for polymorphism?
Answer: c
Explanation: The undefined functions must be defined is a problem, because one may need to implement
few undefined functions from abstract class, but he will have to define each of the functions declared in
abstract class. Being useless task, it is a problem sometimes.
Answer: d
Explanation: It never increases function definition overhead, one way or another if you don’t use
polymorphism, you will use the definition in some other way, so it actually helps to write efficient codes.
12. If 2 classes derive one base class and redefine a function of base class, also overload some operators
inside class body. Among these two things of function and operator overloading, where is
polymorphism used?
Answer: d
Explanation: Both of them are using polymorphism. It is not a necessary that polymorphism can be used
only once in a program, it can be used anywhere, any number of times in a single program.
a. Derived class should provide definition for all the pure virtual functions
b. Derived class also become abstract if fails to implement pure virtual functions
c. Objects of derived class can’t be created if it fails to implement pure virtual functions
d. All of these
ANSWER: All of these
14. If a class contains pure virtual function, then it is termed as____________________ .
a. Virtual class
b. Sealed class
c. Pure Local class
d. Abstract Class
ANSWER: Abstract Class
15. When a virtual function is redefined by the derived class, it is called___________.
a. Overloading
b. Overriding
c. Rewriting
d. All of these
ANSWER: Overriding
a) 1
b) 2
c) 3
d) 4
Answer: b
Explanation: There are two groups of output operation in c++. They are formatted output and unformatted
output.
2. Pick out the correct objects about the instantiation of output stream.
a) cout
b) cerr
c) clog
d) all of the mentioned
Answer: d
Explanation: cout, cerr and clog are the standard objects for the instantiation of output stream class.
3. What is meant by ofstream in c++?
a) Writes to a file
b) Reads from a file
c) Writes to a file & Reads from a file
d) None of the mentioned
Answer: a
Explanation: ofstream is a stream class to write on files.
4. How many types of output stream classes are there in c++
a) 1
b) 2
c) 3
d) 4
Answer: c
Explanation: There are three output stream classes in c++. They are ostream, ofstream and ostrstream.
a) stream
b) streambuf
c) memory
d) none of the mentioned
Answer: b
Explanation: If you construct an object of class ostream, you must specify a streambuf object to the
constructor.
a) >
b) >>
c) <
d) <<
Answer: b
Explanation: The operator of extraction is >> and it is used on the standard input stream.
Answer: a
Explanation: cin will stop its extraction when it encounters a blank space.
a) cout
b) cin
c) coi
d) none of the mentioned
Answer: b
Explanation: cin is mainly used to get the input during the runtime.
a) 1
b) 2
c) 2 or 3
d) 3
Answer: c
Explanation: There are two or three parameters in getline() function. They are a pointer to an array of
characters and maximum number of characters and an optional delimiter.
a) inline
b) getline
c) putline
d) none of the mentioned
Answer: b
Explanation: If a user wants to input a sentence with blank spaces, then he may use the function getline.
a) cpp
b) h
c) hf
d) none of the mentioned
Answer: b
Explanation: .h extensions are used for user defined header files. To include a user defined header file one
should use #include”name.h” i.e. enclosed within double quotes.
13. Which of the following keyword is used to declare the header file?
a) include
b) exclude
c) string
d) namespace
Answer: a
Explanation: The include keyword is used to include all the required things to execute the given code in the
program.
Answer: a
Explanation: The iostream.h is used in the older versions of c++ and iostream is evolved from it in the std
namespace.
a) prototype
b) implementation
c) declarations
d) none of the mentioned
Answer: c
Explanation: In the header file, we define something that to be manipulated in the program.
a) base class
b) abstract class
c) method
d) none of the mentioned
Answer: a
Explanation: None
2. Which value is placed in the base class?
a) derived values
b) default type values
c) both default type & derived values
d) none of the mentioned
Answer: b
Explanation: We can place the default type values in a base class and overriding some of them through
derivation.
a) 1
b) 2
c) 4
d) no memory needed
Answer: d
Explanation: classes that contain only type members, nonvirtual function members, and static data members
do not require memory at run time.
4. How many kinds of entities are directly parameterized in c++?
a) 1
b) 2
c) 3
d) 4
Answer: c
Explanation: C++ allows us to parameterize directly three kinds of entities through templates: types,
constants, and templates.
5. How many kinds of parameters are there in C++?
a) 1
b) 2
c) 3
d) None of the mentioned
Answer: c
Explanation: There are three kinds of parameters are there in C++. They are type, non-type, template.
6. Which keyword is used to handle the expection?
a) try
b) throw
c) catch
d) none of the mentioned
Answer: c
Explanation: When we found a exception in the program, We need to throw that and we handle that by using
the catch keyword.
7. Which is used to throw a exception?
a) throw
b) try
c) catch
d) none of the mentioned
Answer: a
Explanation: throw keyword is used to throw an exception.
eg:
if(divisor == 0){
throw “Divide by zero error”;
}
Answer: b
Explanation: finally keyword will be executed at the end of all the exception.
Answer: a
Explanation: User defined exceptions can be done by inheriting and overriding the exception class
functionality.
10. Which exception is thrown by dynamic_cast?
a) bad_cast
b) bad_typeid
c) bad_exception
d) bad_alloc
Answer: a
Explanation: bad_cast exception is thrown by dynamic_cast.
11. What is a function template?
Answer: a
Explanation: None.
a) template parameters
b) template type parameters
c) template type
d) none of the mentioned
Answer: b
Explanation: During runtime, We can choose the appropriate type for the function
and it is called as template type parameters.
a) you only need to write one function, and it will work with many different types
b) it will take a long time to execute
c) duplicate code is increased
d) none of the mentioned
Answer: a
Explanation: Because of template type parameters, It will work with many types and saves a lot of time.
14. What can be passed by non-type template parameters during compile time?
a) int
b) float
c) constant expression
d) none of the mentioned
Answer: c
Explanation: Non-type template parameters provide the ability to pass a constant expression at compile time.
The constant expression may also be an address of a function, object or static class member.
Answer: c
Explanation: None.
a) <string>
b) <regex>
c) <ios>
d) None of the mentioned
Answer: c
Explanation: The standard header files for string is string and regex. So the wrong one presented here is ios.
2. Which is best for coding the standard library for c++?
Answer: d
Explanation: None.
3. What is meant by vector in the container library contains?
Answer: a
Explanation: vector in the container library contains sequence container that manipulates and encapsulates
dynamic size arrays.
4. Pick out the wrong header file.
a) <algorithm>
b) <containers>
c) <iterators>
d) <process>
Answer: d
Explanation: There is no header file named <process> in C++.
a) It is the collection of class definitions for standard data structures and a collection of algorithms
b) It is a header file
c) Collection of algorithms
d) None of the mentioned
Answer: a
Explanation: It is the collection of class definitions for standard data structures. This part of the library was
derived from the Standard Template Library.
6. Pick out parameter for rehash method in unordered_set in c++?
a) count
b) size
c) hash
d) none of the mentioned
Answer: a
Explanation: count is used to return the new number of buckets.
Answer: a
Explanation: <exception> header file contains standard exception files used for exception handling in a C++
program.
8.How many items are there in sequence container?
a) 2
b) 3
c) 4
d) 5
Answer: d
Explanation: There are five items in sequence container. They are array, vector, list, forward_list and
dequeue.
9. Which of the following class template are based on arrays?
a) vector
b) list
c) dequeue
d) both vector & dequeue
Answer: d
Explanation: Class template vector and class template dequeue both are based on arrays.
10. Which of the following will return the new element at the end of container?
a) front
b) back
c) push_back
d) pop_back
Answer: b
Explanation: Q3: back() in containers are used to access the last element of the sequence.
11. What do associate containers implement?
a) Arrays
b) Associative arrays
c) Functional Arrays
d) None of the mentioned
Answer: b
Explanation: Associative containers refer to a group of class templates in the standard library of the C++
programming language that implement ordered associative arrays.
12. By using which of the following the elements in the associate container can
be efficiently accessed?
a) Key
b) Position
c) Both Key & Position
d) None of the mentioned
Answer: a
Explanation: Associative containers are designed to be especially efficient in accessing its elements by their
key, as opposed to sequence containers which are more efficient in accessing elements by their position.
a) 2
b) 3
c) 4
d) 5
Answer: c
Explanation: There are 4 items presented in the associate container. They are set, multiset, map and
multimap.
14. What do associate containers implement?
a) Arrays
b) Associative arrays
c) Functional Arrays
d) None of the mentioned
Answer: b
Explanation: Associative containers refer to a group of class templates in the standard library of the C++
programming language that implement ordered associative arrays.
15. By using which of the following the elements in the associate container can
be efficiently accessed?
a) Key
b) Position
c) Both Key & Position
d) None of the mentioned
Answer: a
Explanation: Associative containers are designed to be especially efficient in accessing its elements by their
key, as opposed to sequence containers which are more efficient in accessing elements by their position.