You are on page 1of 24

http://www.careerride.com/mcq-daily/c-test-questions-set-3-50.

aspx

1) Which of the following is not used to seek a file pointer?

a. ios::cur
b. ios::set
c. ios::end
d. ios::beg
2) During dynamic memory allocation in CPP, new operator returns _________ value if
memory allocation is unsuccessful.

a. False
b. NULL
c. Zero
d. None of these
3) We can create objects of the abstract class.

a. True
b. False
4) Which of the followings is/are pointer-to-member declarator?

a. ->*
b. .*
c. ::*
d. both a and b
5) Default value of static variable is_____ .

a. 0
b. 1
c. Garbage value
d. Compiler dependent
6) ________ are used to format the data display in CPP.

a. Iterators
b. Punctuators
c. Manipulators
d. Allocators
7) Reusability of the code can be achieved in CPP through ______ .

pg. 1
a. Polymorphism
b. Encapsulation
c. Inheritance
d. Both a and c
8) By default, members of the class are ____________ in nature.

a. protected
b. private
c. public
d. static
10) Which of the following is CPP style type-casting?

a. per = total/(float)m
b. per = total/float(m)
c. per = (float)total/m
d. None of these
11) If a program uses Inline Function, then the function is expanded inline at
___________.

a. Compile time
b. Run time
c. Both a and b
d. None of these
12) In CPP, the size of the character array should be one larger than the number of
characters in the string.

a. True
b. False
13) Which of the following is/are valid ways to allocate memory for an integer by dynamic
memory allocation in CPP?

a. int *p = new int(100);


b. int *p; p = new int; *p = 100;
c. int *p = NULL; p = new int; *p=100;
d. Only 1,2
e. All of these
14) Which of the following is the perfect set of operators that can’t be overloaded in CPP
?

a. +=, ?, :: , >>
b. >>, <<, ?, *, sizeof()

pg. 2
c. :: , . , .* , ?:
d. :: , ->, * , new, delete
15) Static variable in a class is initialized when _____ .

a. every object of the class is created.


b. last object of the class is created.
c. first object of the class is created.
d. No need to initialize static variable.
16) To perform File I/O operations, we must use _____________ header file.

a. < ifstream>
b. < ofstream>
c. < fstream>
d. Any of these
17) An exception is thrown using _____________ keyword in CPP.

a. throws
b. throw
c. threw
d. Thrown
18) Which of the followings is/are not a manipulator/s ?

1. flush
2. base
3. ends
4. oct
5. bin
6. skipws

a. Only 1, 6
b. Only 1,4,6
c. Only 1,3,6
d. Only 2,5
19) If default constructor is not defined, then how the objects of the class will be created?

a. The compiler will generate error


b. Error will occur at run-time.
c. Compiler provides its default constructor to build the object.
d. None of these
20) Is it mandatory to invoke/call a constructor for creating an object?

pg. 3
a. Yes
b. No
21) Members of the class can be declared with auto, extern or register storage classes.

a. True
b. False
22) C structure differs from CPP class in regards that by default all the members of the
structure are __________ in nature.

a. private
b. protected
c. public
d. None of these
23) Which of the following best defines the syntax for template function ?

a. Template
b. Template return_type Function_Name(Parameters)
c. Both a and b
d. None of these
24) Generic pointers can be declared with__________ .

a. auto
b. void
c. asm
d. None of these
25) Which of the followings are true about constructors?

1. A class can have more than one constructor.


2. They can be inherited.
3. Their address can be referred.
4. Constructors cannot be declared in protected section of the class.
5. Constructors cannot return values.

a. Only 1,2,4
b. 1,2,4,5
c. 1,3,5
d. 1,4,5

pg. 4
TEST 2:
1) Which of the following are true about static member function?

1. They can access non-static data members.


2. They can call only other static member functions.
3. They can access global functions and data.
4. They can have this pointer.
5. They cannot be declared as const or volatile.

a. Only 2
b. Only 2,5
c. Only 2,3,4,5
d. Only 2 , 3 , 5
e. All of these
2) Static variable must be declared in public section of the class.

a. True
b. False
3) By default, if a function with minimum lines of code is declared and defined inside the
class becomes Inline function.

a. True
b. False
4) class X, class Y and class Z are derived from class BASE. This is ______ inheritance.

a. Multiple
b. Multilevel
c. Hierarchical
d. Single
5) When base class is derived in protected mode, then_____________ .

1. public members of base class become private members of derived class.


2. public members of base class become protected members of derived class.
3. public members of base class become public members of derived class.
4. protected members of base class become protected members of derived class.
5. protected members of base class become private members of derived class.
6. protected members of base class become public members of derived class.

pg. 5
a. Only 1, 5
b. Only 1, 6
c. Only 2, 6
d. Only 2, 4
6) Can we have overloading of the function templates?

a. Yes
b. No
7) Streams that will be performing both input and output operations must be declared as
class _________ .

a. iostream
b. fstream
c. stdstream
d. Stdiostream
8) Exception handlers are declared with ____________ keyword.

a. Try
b. catch
c. throw
d. Finally
9) Which of the following statements are true about Catch handler?

1. It must be placed immediately after try block T.


2. It can have multiple parameters.
3. There must be only one catch handler for every try block.
4. There can be multiple catch handler for a try block T.
5. Generic catch handler can be placed anywhere after try block.

a. Only 1, 4, 5
b. Only 1, 2, 3
c. Only 1, 4
d. Only 1, 2
10) Static variable declared in a class are also called_________ .

a. instance variable
b. named constant
c. global variable
d. class variable
11) Which of the following operator is used to release the dynamically allocated memory
in CPP?

pg. 6
a. remove
b. free
c. delete
d. both b and c
12) Which of the following is not a false statement about new operator?

a. It can’t be overloaded.
b. It returns garbage value when memory allocation fails.
c. It automatically computes the size of the data object.
d. All of these
13) Private members of the class are accessible only to the members of the same class.

a. True
b. False
14) Run time polymorphism can be achieved with______ .

a. Virtual Base class


b. Container class
c. Virtual function
d. Both a and c
15) To create an output stream, we must declare the stream to be of class ___________ .

a. ofstream
b. ifstream
c. iostream
d. None of these
16) Catch handler can have multiple parameters.

a. True
b. False
17) Inline functions may not work ______ .

1. If function contain static variables.


2. If function contain global and register variables.
3. If function returning value consists looping construct(i.e. for, while).
4. If inline functions are recursive.
5. If function contains const value.

a. Only 1,4,5
b. Only 2,3,5
c. Only 1,3,4
d. All of these

pg. 7
18) Which of the followings is/are not false about friend function ?

1. It can be called / invoked with class object.


2. It has objects as arguments.
3. It can have built-in types as arguments.
4. It must declared only in public part of a class.
5. It does not have this pointer as an argument.

a. Only 2,4
b. Only 1,2,5
c. Only 2,3,5
d. All of these
19) Predict the output:

int x = 786;
cout << setfill(‘*’) << setw(6) << x;

a. 786***
b. **786
c. ***786
d. ******
20) Default return type of functions in CPP is ____ .

a. void
b. long
c. char
d. Int
21) Default values for a function are need to be specified from left to right only.

a. True
b. False
22) During a class inheritance in CPP, if the visibility mode or mode of derivation is not
provided, then by default visibility mode is ___________.

a. public
b. protected
c. private
d. Friend
23) The derivation of Child class from Base class is indicated by ____ symbol.

pg. 8
a. ::
b. :
c. ;
d. |
24) If we have object from fstream class, then what is the default mode of opening the file?

a. ios::in|ios::out
b. ios::in|ios::out|ios::trunc
c. ios::in|ios::trunc
d. Default mode depends on compiler
25) __________ is return type of is_open() function.

a. int
b. bool
c. float
d. char *

TEST3:
1) Public data members and member functions of the class are accessible ONLY to the
member functions of that class.

a. True
b. False
2) Only functions of the class can access the data of the class and they(functions) provides
the interface between data, objects and the program. This kind isolation of the data from
direct access by the program is called _______________ .

a. Data Abstraction
b. Data Hiding
c. Data Binding
d. Data Encapsulation
3) A Constructor that does not have any parameters is called____________ Constructor.

a. Custom
b. Dynamic
c. Static
d. Default
4) If we have object from ofstream class, then default mode of opening the file is _____ .

pg. 9
a. ios::in
b. ios::out
c. ios::in|ios::trunc
d. ios::out|ios::trunk
5) _______________ is a member function that is declared within a base class and
redefined by derived class.

a. virtual function
b. static function
c. friend function
d. const member function
6) Syntax for Pure Virtual Function is ______________ .

a. virtual void show()==0


b. void virtual show()==0
c. virtual void show()=0
d. void virtual show()=0
7) Logical expressions produce ____________ type results.

a. explicit
b. garbage
c. bool
d. static
8) We can initialize a value of static variable of a class only when its object is created. No
other initialization is permitted.

a. True
b. False
9) When a base class is privately inherited by the derived class, then_____________ .

a. protected members of the base class become private members of derived class
b. public members of the base class become private members of derived class
c. both a and b
d. only b
10) What is the difference between protected and private access specifiers in inheritance?

a. private member is not inheritable and not accessible in derived class.


b. protected member is inheritable and also accessible in derived class.
c. Both are inheritable but private is accessible in the derived class.
d. Both are inheritable but protected is not accessible in the derived class.
11) A friend function does not have 'this' pointer associated with it.

pg. 10
a. True
b. False
12) In nested try blocks, if both inner and outer catch handlers are not able to handle the
exception, then ______________ .

a. Compiler executes only executable statements of main().


b. Compiler issues compile time errors about it.
c. Program will be executed without any interrupt.
d. Program will be terminated abnormally.
13) Throwing an unhandled exception causes standard library function then _________ to
be invoked.

a. stop()
b. aborted()
c. terminate()
d. Abandon()
14) In CPP, it is mandatory and must to initialize const variables.

a. True
b. False
15) When a class is defined inside any function or block, it is called ___________ .

a. Nested class
b. Block class
c. Local class
d. It is not possible
16) Which of the followings are false statements about Local class?

1. A local class type name can only be used in the enclosing function
2. All the methods of Local classes must be defined inside the class only
3. A Local class can contain static data members.
4. A Local class may contain static functions.
5. Non-static variables of the enclosing function are not accessible inside local classes.
6. Local classes cannot access global types, variables and functions.

a. Only 1,3
b. Only 3, 6
c. Only 2 , 4 , 6
d. None of these
17) Due to ios::trunc mode, the file is truncated to zero length.

pg. 11
a. True
b. False
18) A const object of a class can call non-const member function of the class.

a. True
b. False
19) If an argument to a function is declared as const, then _______ .

a. function can modify the argument.


b. Function can’t modify the argument.
c. const argument to a function is not possible.
d. None of these
20) Return type of uncaught_exception() is ________________ .

a. int
b. bool
c. char *
d. double
21) Can we write throw clause inside catch handler?

a. Yes
b. No
22) Default values for a function are specified when ____ .

a. function is defined
b. function is declared
c. Both a and b
d. None of these
23) Can member functions of one class be friend functions of another class?

a. Yes
b. No
24) Predict the output:

float x= 3.1496;
cout << setpricision(2) << x;

a. 3.14
b. 3.15

pg. 12
c. 3.00
d. None of these
25) In case of binary operator overloading with member function, which of following
statement should be taken into consideration?

a. Right hand operand must be object.


b. Left hand operand must be object.
c. Both the operands must be objects.
d. All of these should be considered.

TESt4:
1) Can constructors be overloaded?

a. Yes
b. No
2) Assume class TEST. Which of the following statements is/are responsible to invoke
copy constructor?

a. TEST T2(T1)
b. TEST T4 = T1
c. T2 = T1
d. both a and b
e. All of these
3) When overloading unary operators using Friend function,it requires_____ argument/s.

a. Zero
b. One
c. Two
d. None of these.
4) In CPP program, Can we declare and define a user defined function inside a struct as
we do in a class ?

a. Yes
b. No
c. Can’t say
5) ____________ refers to the act of representing only essential features without including
the background details.

a. Data Hiding
b. Data Encapsulation

pg. 13
c. Data Abstraction
d. All of these
6) Runtime polymorphism is achieved only when a virtual function is accessed through a
pointer to the base class.

a. True
b. False
7) Find the wrong statement/s about Abstract Class.

a. We can’t create its objects.


b. We can’t create pointers to an abstract class.
c. It contains at least one pure virtual function.
d. We can create references to an abstract class.
8) Assigning one or more function body to the same name is called ____________ .

a. Function Overriding
b. Function Overloading
c. Both a and b
d. None of the above
9) Function overloading can also be achieved if two or more functions differ only in their
return types.

a. True
b. False
10) In nested try block, if inner catch handler gets executed, then _____________ .

a. Program execution stops immediately.


b. Outer catch handler will also get executed.
c. Compiler will jump to the outer catch handler and then executes remaining executable
statements of main().
d. Compiler will execute remaining executable statements of outer try block and then the
main().
11) A function can be declared as friend maximum only in two classes.

a. True
b. False
12) Which of the following statements are not true about destructor?

1. It is invoked when object goes out of the scope


2. Like constructor, it can also have parameters
3. It can be virtual

pg. 14
4. It can be declared in private section
5. It bears same name as that of the class and precedes Lambda sign.

a. Only 2, 3, 5
b. Only 2, 3, 4
c. Only 2, 4, 5
d. Only 3, 4, 5
13) When a child class inherits traits from more than one parent class, this type of
inheritance is called _______________ inheritance.

a. Hierarchical
b. Hybrid
c. Multilevel
d. Multiple
14) In case of inheritance where both base and derived class are having constructor and
destructor, then which if the following are true ?

1. Constructors are executed in their order of derivation


2. Constructors are executed in reverse order of derivation
3. Destructors are executed in their order of derivation
4. Destructors are executed in reverse order of derivation

a. Only 2 ,4
b. Only 1 , 3
c. Only 1 , 4
d. Only 2, 3
15) __________________ is the OOP feature and mechanism that binds together code and
the data it manipulates, and keep both safe from outside world.

a. Data Binding
b. Data Encapsulation
c. Data Storing
d. Data Abstraction
16) Which of the followings is/are not keyword/s in CPP?

1. asm
2. boolean
3. mutable
4. export
5. constant_cast

a. Only 5
b. Only 1 and 4

pg. 15
c. Only 1,2 and 5
d. Only 2 and 5
17) We can create objects of the abstract class.

a. True
b. False
18) Which of the followings are true about Virtual functions?

a. They must be non-static member function of the class


b. They cannot be friends
c. Constructor Functions cannot be virtual
d. All of these
19) If a class contains static variable, then every object of the class has its copy of static
variable.

a. True
b. False
20) Which of the following are member dereferencing operators in CPP?

1. *
2. ::
3. ->*
4. ::*
5. ->

a. Only 1, 3, 4
b. Only 1 and 5
c. Only 3 and 4
d. Only 3,4,5
21) In Multipath inheritance, in order to remove duplicate set of records in child class, we
___________ .

a. Write Virtual function in parent classes


b. Write virtual functions is base class
c. Make base class as virtual base class
d. All of these
22) If base class has constructor with arguments, then it is ________________ for the
derived class to have constructor and pass the arguments to base class constructor.

a. Optional
b. Mandatory

pg. 16
c. Compiler dependent
d. Error
23) Using friend operator function, following perfect set of operators may not be
overloaded.

a. = , ( ) , [ ] , ->
b. <<, = = , [ ] , >>
c. ?, = , ( ) , ++
d. None of these
24) An operator function is created using _____________ keyword.

a. iterator
b. allocator
c. constructor
d. operator
25) Classes in CPP are________ .

a. derived data types


b. User defined data types
c. built-in data types
d. All of these

TEST4:
1) Can we define our exceptions in CPP?

a. Yes
b. No
2) The code of statements which may cause abnormal termination of the program should
be written under_________ block.

a. Try
b. catch
c. Finally
d. None of these
3) Object based language differs from object oriented language as it does not support
features _____ .

1. Encapsulation
2. Inheritance
3. Dynamic Binding

pg. 17
4. Abstraction
5. Polymorphism

a. only 3 ,4
b. only 1,3,5
c. 2,4,5
d. Only 2,3
4) When a virtual function is redefined by the derived class, it is called___________.

a. Overloading
b. Overriding
c. Rewriting
d. All of these
5) In any ways, Non-member function cannot have access to the private data of the class.

a. True
b. False
6) In CPP, dynamic memory allocation is done using ______________ operator.

a. calloc()
b. malloc()
c. allocate
d. New
7) Can we allocate memory for the objects dynamically in CPP?

a. Yes
b. No
8) If the derived class is struct, then default visibility mode is _______ .

a. public
b. protected
c. private
d. struct can’t inherit class
9) Which of the following manipulator is used for the representing octal equivalent of a
given decimal number?

a. oct
b. setbase(8)
c. tobase(8)
d. both a and b
e. all a, b, c

pg. 18
10) Which of the following is not a casting operator in CPP?

a. explicit_cast
b. static_cast
c. dynamic_cast
d. reinterpret_cast
11) ___________ header file is used for manipulators.

a. < iomanipulator.h>
b. < stdiomanip.h>
c. < stdmanip.h>
d. < iomanip.h>
12) While redefining a virtual function in the derived class, if its prototype is changed then
___________________ .

a. It will be overloaded by the compiler


b. Its virtual nature will be lost
c. both a and b
d. Compiler will generate “Prototype mismatch error”
13) const member function does not allow to modify/alter value of any data member of the
class.

a. True
b. False
14) In a program, If there exists a function template with two parameters and normal
function say void add(int , int), so add(3,4) will _____________________ .

a. Invoke function template body as it is generic one


b. Invokes normal function as it exactly matches with its prototype
c. Not be called and Compiler issues warning
d. Not be called and Compiler issues ambiguity in calling add()
15) Can struct be used as Base class for inheritance ?

a. Yes
b. No
16) In case of inheritance where both base and derived class are having constructors,
when an object of derived class is created then___________ .

a. constructor of derived class will be invoked first


b. constructor of base class will be invoked first
c. constructor of derived class will be executed first followed by base class
d. constructor of base class will be executed first followed by derived class

pg. 19
17) Which of the following is not a file opening mode ____ .

a. ios::ate
b. ios::nocreate
c. ios::noreplace
d. ios::truncate
18) Attempting to throw an exception that is not supported by a function call results in
calling _____________ library function.

a. indeterminate()
b. unutilized()
c. unexpected()
d. unpredicted()
19) How can we restrict a function to throw certain exceptions?

a. Defining multiple try and catch block inside a function


b. Defining generic function within try block
c. Defining function with throw clause
d. It is not possible in CPP to restrict a function
20) Is it possible to define a constructor with default arguments?

a. Yes
b. No
21) The purpose of explicit keyword is to tell the compiler that a certain constructor may
not be used to implicitly cast an expression to its class type.

a. True
b. False
22) Scope resolution operator is used______ .

a. to resolve the scope of global variables only


b. to resolve the scope of functions of the classes only
c. to resolve scope of global variables as well as functions of the classes
d. None of these
23) In case of operator overloading, operator function must be ______ .

1. Static member functions


2. Non- static member functions
3. Friend Functions

a. Only 2
b. Only 1, 3

pg. 20
c. Only 2 , 3
d. All 1 , 2, 3
24) A try block can be nested under another try block.

a. True
b. False
25) In nested try blocks, there is no need to specify catch handler for inner try block.
Outer catch handler is sufficient for the program.

a. True
b. False

TEST5:
1) We can prevent a function from throwing any exceptions.

a. True
b. False
2) Functions called from within a try block may also throw exception.

a. True
b. False
3) The explicit keyword is an optional decoration for the constructors that takes
exactly_____argument.

a. No argument
b. Two
c. Three
d. One
4) A class can contain objects of other classes and this phenomenon is called_________ .

a. Relationship
b. Object Association
c. Containership
d. None of these
5) Can we alter/modify the values of data members of a class inside const member
function?

a. Yes
b. No

pg. 21
6) 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
7) If inner catch handler is not able to handle the exception then__________ .

a. Compiler will look for outer try handler


b. Program terminates abnormally
c. Compiler will check for appropriate catch handler of outer try block
d. None of these
8) Generic catch handler is represented by ______________ .

a. catch(..,)
b. catch(---)
c. catch(…)
d. catch( void x)
9) Which one is suitable syntax for function template?

a. template< class T> return_type Function_Name(parameters)


b. template< typename T> return_type Function_Name(parameters)
c. both a and b
d. None of these
10) It is not possible to combine two or more file opening mode in open () method.

a. True
b. False
11) Private members of the class are not inheritable.

a. True
b. False
12) While overloading binary operators using member function, it requires ___
argument/s.

a. Zero
b. One
c. Two
d. Three
13) If abstract class is inherited by derived class, then_______________ .

pg. 22
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
14) By default, all the files are opened in ___________mode .

a. Binary
b. Text
c. Can’t say
15) Generic catch handler must be placed at the end of all the catch handlers.

a. True
b. False
16) An exception can be of only built-In type.

a. True
b. False
17) The CPP compiler supports automatic type conversions for the user defined
datatypes.

a. True
b. False
18) Can a class be declared/defined inside another class ?

a. Yes
b. No
19) Can we pass parameters to base class constructor though derived class or derived
class constructor?

a. Yes
b. No
20) _________________are used for generic programming.

a. Inheritance
b. Virtual Functions
c. Templates
d. None of these
21) Irrespective of exception occurrence, catch handler will always get executed.

a. True
b. False

pg. 23
22) In CPP, cin and cout are the predefined stream __________ .

a. Operator
b. Functions
c. Objects
d. Data types
23) Object oriented programming employs_________ programming approach.

a. top-down
b. procedural
c. bottom-up
d. all of these.
24) Constant variables can be created in CPP by using ________ .

a. enum
b. const
c. #define
d. All of these
e. None of these
25) A virtual function that has no definition within the base class is called____________.

a. Pure virtual function


b. Pure static function
c. Pure Const function
d. Friend function

pg. 24

You might also like