Classes And Objects In C Plus Plus

Name: _____________________

Date: _____________________

Instructions: Answer all questions. Write your answers clearly in the space provided.

Question 1:

Operator overloading is . . . . . . . .

A. making c++ operator works with objects
B. giving new meaning to existing operator
C. making the new operator
D. adding operation to the existing operators
Answer: _________
Question 2:

What do we need to do to pointer for overloading the subscript operator?

A. reference pointer
B. dereference pointer
C. store it in heap
D. memory locator
Answer: _________
Question 3:

Pick out the compound assignment statement.

A. a = a – 5
B. a = a / b
C. a -= 5
D. a = a + 5
Answer: _________
Question 4:

Identify the correct statement.

A. typedef does not create different types. It only creates synonyms of existing types
B. typedef create different types
C. typedef create own types
D. typedef will not creates synonyms of existing types
Answer: _________
Question 5:

What is the use of function call operator?

A. overloading the methods
B. overloading the objects
C. overloading the parameters
D. overloading the string
Answer: _________
Question 6:

Pick the incorrect statement about inline functions in C++?

A. They reduce function call overheads
B. These functions are inserted/substituted at the point of call
C. Saves overhead of a return call from a function
D. They are generally very large and complicated function
Answer: _________
Question 7:

What is a class in C++?

A. A collection of functions
B. A reserved keyword in C++
C. A blueprint for creating objects
D. A way to declare arrays of data
Answer: _________
Question 8:

Which keyword is used to create an object of a class in C++?

A. new
B. create
C. object
D. None of the above
Answer: _________
Question 9:

What is an object in C++?

A. A reserved keyword in C++
B. An instance of a class
C. A way to declare arrays of data
D. None of the above
Answer: _________
Question 10:

What is the purpose of a constructor in C++?

A. To hide the implementation details of a class
B. To create multiple instances of a class
C. To initialize the object's data members
D. To destroy the object
Answer: _________
Question 11:

Which access specifier allows members of a class to be accessed from outside the class in C++?

A. private
B. protected
C. friend
D. public
Answer: _________
Question 12:

What is the correct syntax to define a member function outside the class in C++?

A. returnType functionName() {}
B. returnType className::functionName() {}
C. returnType className::functionName()
D. returnType functionName(className) {}
Answer: _________
Question 13:

What is the process of combining data and functions into a single unit called in C++?

A. Encapsulation
B. Inheritance
C. Polymorphism
D. Abstraction
Answer: _________
Question 14:

What does the 'this' pointer refer to in C++?

A. Pointer to the base class object instance
B. Pointer to the next object instance
C. Pointer to the previous object instance
D. Pointer to the current object instance
Answer: _________
Question 15:

Which keyword is used to declare a member function of a class as constant in C++?

A. static
B. final
C. const
D. virtual
Answer: _________
Question 16:

What is the purpose of the 'static' keyword in C++ class members?

A. To initialize objects of a class
B. To create a single copy of the member shared by all objects
C. To create multiple instances of a class
D. None of the above
Answer: _________
Question 17:

Which is used to tell the computer that where a pointer is pointing to?

A. dereference
B. reference
C. heap operations
D. binary operations
Answer: _________
Question 18:

What is the scope of typedef defined data types?

A. inside that block only
B. whole program
C. outside the program
D. main function
Answer: _________
Question 19:

Which is called ternary operator?

A. ?:
B. &&
C. |||
D. ===
Answer: _________
Question 20:

How the objects are self-referenced in a member function of that class.

A. Using a special keyword object
B. Using this pointer
C. Using * with the name of that object
D. By passing self as a parameter in the member function
Answer: _________
Question 21:

How many objects can present in a single class?

A. 1
B. 2
C. 3
D. as many as possible
Answer: _________
Question 22:

In which form does the function call operator can be overloaded?

A. static member function
B. non-static member function
C. dynamis_cast
D. static_cast
Answer: _________
Question 23:

Which is the correct example of a binary operator?

A. ++
B.
C. Dereferencing operator(*)
D. +
Answer: _________
Question 24:

Which of the following operator can be used to overload when that function is declared as friend function?

A. []
B. ()
C. ->
D. |=
Answer: _________
Question 25:

The data members and functions of a class in C++ are by default . . . . . . . .

A. protected
B. private
C. public
D. public & protected
Answer: _________
Question 26:

How many arguments will the subscript operator will take for overloading?

A. 1
B. 2
C. 0
D. as many as possible
Answer: _________
Question 27:

How are types therein user-defined conversion?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 28:

What is string objects in C++?

A. Stream of alphabets
B. A stream of well-defined characters
C. Stream of characters
D. A stream of characters terminated by x00
Answer: _________
Question 29:

Pick out the other definition of objects.

A. member of the class
B. associate of the class
C. attribute of the class
D. instance of the class
Answer: _________
Question 30:

Where does keyword ‘friend’ should be placed?

A. function declaration
B. function definition
C. main function
D. block function
Answer: _________
Question 31:

What is a binary operator?

A. Operator that performs its action on a single operand
B. Operator that performs its action on two operand
C. Operator that performs its action on three operand
D. Operator that performs its action on any number of operands
Answer: _________
Question 32:

Which option is best to eliminate the memory problem?

A. use smart pointers
B. use raw pointers
C. use virtual destructor
D. use smart pointers & virtual destructor
Answer: _________
Question 33:

Pick out the correct statement.

A. virtual functions does not give the ability to write a templated function
B. virtual functions does not give the ability to rewrite a templated function
C. virtual functions does give the ability to write a templated function
D. virtual functions does not give the ability to rewrite a simple function
E. Increment operator ++ adds 1 to its operand
F. Increment operator ++ adds 2 to its operand
G. Decrement operator ++ subtracts 1 to its operand
H. Decrement operator ++ subtracts 3 to its operand
I. the null pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to null
J. the null pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to the memory address
K. rvalue equivalent to the value at the pointer address
L. null pointer will not return anything
M. subscript operator has a higher precedence than the assignment operator
N. subscript operator has a lower precedence than the assignment operator
O. subscript operator is used with string elements
P. subscript operator is used with char elements
Q. Pre Increment is faster than post-increment
R. post-increment is faster than Pre Increment
S. pre increment is slower than post-increment
T. pre decrement is slower than post-increment
Answer: _________
Question 34:

What do we need to use when we have multiple subscripts?

A. operator()
B. operator[]
C. operator
D. operator<>
Answer: _________
Question 35:

Which of the following operator cannot be used to overload when that function is declared as friend function?

A. -=
B. ||
C. ==
D. []
Answer: _________
Question 36:

In Linux, how do the heaps and stacks are managed?

A. ram
B. secondary memory
C. virtual memory
D. static memory
Answer: _________
Question 37:

Which of the following is not a function of complex values?

A. real
B. imag
C. norm
D. cartesian
Answer: _________
Question 38:

subscript operator is used to access which elements?

A. string
B. char
C. array
D. float
Answer: _________
Question 39:

Which keyword is used to represent a friend function?

A. friend
B. Friend
C. friend_func
D. Friend_func
Answer: _________
Question 40:

What is Character-Array?

A. array of alphabets
B. array of well-defined characters
C. array of characters
D. array of characters terminated by x00
Answer: _________
Question 41:

Pick the incorrect statements out of the following.

A. Operator overloading does not disturbs the precedence of operators
B. Arity of operators can be changed using operator overloading
C. No new operators can be created
D. All of the mentioned
Answer: _________
Question 42:

Which keyword is used to define the user defined data types?

A. def
B. union
C. typedef
D. type
Answer: _________
Question 43:

Which of the following is correct about friend functions?

A. Friend functions use the dot operator to access members of a class using class objects
B. Friend functions can be private or public
C. Friend cannot access the members of the class directly
D. All of the mentioned
Answer: _________
Question 44:

Which function is used to get the length of a string object?

A. str.length()
B. str.size()
C. str.max_size()
D. both size() and length() function
Answer: _________
Question 45:

How many types of user-defined data type are in c++?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 46:

Which is the correct statement about operator overloading?

A. Only arithmetic operators can be overloaded
B. Only non-arithmetic operators can be overloaded
C. Precedence of operators are changed after overlaoding
D. Associativity and precedence of operators does not change
Answer: _________
Question 47:

Which other keywords are also used to declare the class other than class?

A. struct
B. union
C. object
D. both struct & union
Answer: _________
Question 48:

Inline functions are avoided when . . . . . . . .

A. function contains static variables
B. function have recursive calls
C. function have loops
D. all of the mentioned
Answer: _________
Question 49:

What is a friend function in C++?

A. A function which can access all the private, protected and public members of a class
B. A function which is not allowed to access any member of any class
C. A function which is allowed to access public and protected members of a class
D. A function which is allowed to access only public members of a class
Answer: _________
Question 50:

Pick the correct statement.

A. Friend functions are in the scope of a class
B. Friend functions can be called using class objects
C. Friend functions can be invoked as a normal function
D. Friend functions can access only protected members not the private members
E. Macros and inline functions are same thing
F. Macros looks like function calls but they are actually not
G. Inline functions looks like function but they are not
H. Inline function are always large
Answer: _________
Question 51:

How to declare operator function?

A. operator sign
B. operator
C. name of the operator
D. name of the class
Answer: _________
Question 52:

What is the use of functor?

A. It makes the object "callable" like a function
B. It makes the class "callable" like a function
C. It makes the attribute "callable" like a function
D. It makes the argument "callable" like a function
Answer: _________
Question 53:

How many types of representation are in the string?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 54:

Which header file is used to declare the complex number?

A. complexnum
B. complex
C. complex number
D. complexarg
Answer: _________
Question 55:

Pick the other name of operator function.

A. function overloading
B. operator overloading
C. member overloading
D. object overloading
Answer: _________
Question 56:

Which header file is used to include the string object functions in C++?

A. #include <string.h>
B. #include <cstring>
C. #include <string>
D. #include <string.cpp>
Answer: _________
Question 57:

Constructors are used to . . . . . . . .

A. initialize the objects
B. construct the data members
C. both initialize the objects & construct the data members
D. delete the objects
Answer: _________
Question 58:

What is the header file for the string class?

A. #include<ios>
B. #include<str>
C. #include<string>
D. #include<stio>
Answer: _________
Question 59:

Pick the incorrect statement about Character-Array.

A. Character-Array can be terminated by a null character('x00')
B. Character-Array has a static size
C. Character-Array has a dynamic size
D. Character-Array has a threat of array-decay
Answer: _________
Question 60:

What does the data type defined by union will do?

A. It allow one different portion of memory to be accessed as same data types
B. It allow one same portion of memory to be accessed as same data types
C. It allow one different portion of memory to be accessed as different data types
D. It allow one same portion of memory to be accessed as different data types
Answer: _________
Question 61:

What is the name of | operator?

A. sizeof
B. or
C. and
D. modulus
Answer: _________
Question 62:

In which direction does the assignment operation will take place?

A. left to right
B. right to left
C. top to bottom
D. bottom to top
Answer: _________
Question 63:

Which category of data type a class belongs to?

A. Fundamental data type
B. Derived data type
C. User defined derived data type
D. Atomic data type
Answer: _________
Question 64:

Which operator works only with integer variables?

A. increment
B. decrement
C. both increment & decrement
D. binary operator
Answer: _________
Question 65:

How many approaches are used for operator overloading?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 66:

What is the syntax of overloading operator + for class A?

A. A operator+(argument_list){}
B. A operator[+](argument_list){}
C. int +(argument_list){}
D. int [+](argument_list){}
Answer: _________
Question 67:

Which of the following operator can be overloaded?

A. ?:
B. ::
C. .
D. ==
Answer: _________
Question 68:

How to store the large objects in c++ if it extends its allocated memory?

A. memory heap
B. stack
C. queue
D. stack & queue
Answer: _________
Question 69:

How to declare the complex number?

A. (3, 4)
B. complex(3, 4)
C. (3, 4i)
D. (3, 4g)
Answer: _________
Question 70:

Which container in c++ will take large objects?

A. string
B. class
C. vector
D. string & class
Answer: _________
Question 71:

How many types of models are available to create the user-defined data type?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 72:

Which concepts does the Pre Increment use?

A. call by value
B. call by reference
C. queue
D. call by name
Answer: _________
Question 73:

Which of the following is not a modifier function in string class?

A. operator+=()
B. operator[]()
C. push_back()
D. erase()
Answer: _________
Question 74:

In the case of friend operator overloaded functions how many maximum object arguments a unary operator overloaded function can take?

A. 1
B. 2
C. 3
D. 0
Answer: _________
Question 75:

Which of the following operators can't be overloaded?

A. ::
B. +
C.
D. []
Answer: _________
Question 76:

Which of the following statements is NOT valid about operator overloading?

A. Only existing operators can be overloaded
B. The overloaded operator must have at least one operand of its class type
C. The overloaded operators follow the syntax rules of the original operator
D. None of the mentioned
Answer: _________
Question 77:

Where does the object is created?

A. class
B. constructor
C. destructor
D. attributes
Answer: _________
Question 78:

What does the dereference operator will return?

A. rvalue equivalent to the value at the pointer address
B. lvalue equivalent to the value at the pointer address
C. it will return nothing
D. it will return boolean values
Answer: _________
Question 79:

What is the return type of the conversion operator?

A. void
B. int
C. float
D. no return type
Answer: _________
Question 80:

Which functions of a class are called inline functions?

A. All the functions containing declared inside the class
B. All functions defined inside or with the inline keyword
C. All the functions accessing static members of the class
D. All the functions that are defined outside the class
Answer: _________
Question 81:

What will happen when the function call operator is overloaded?

A. It will not modify the functions
B. It will modify the functions
C. It will modify the object
D. It will modify the operator to be interpreted
Answer: _________
Question 82:

How many real types are there in complex numbers?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 83:

Which of these following members are not accessed by using direct member access operator?

A. public
B. private
C. protected
D. both private & protected
Answer: _________
Question 84:

When struct is used instead of the keyword class means, what will happen in the program?

A. access is public by default
B. access is private by default
C. access is protected by default
D. access is denied
Answer: _________
Question 85:

Pick out the correct option.

A. References automatically dereference without needing an extra character
B. References automatically dereference with an extra character
C. Reference will not dereference
D. Reference automatically dereference with extra space and character
Answer: _________
Question 86:

What is the identifier given to string class to declare string objects?

A. String
B. string
C. STRING
D. Any of the above can be used
Answer: _________
Question 87:

Which is used to do the dereferencing?

A. pointer without asterix
B. value without asterix
C. pointer with asterix
D. value with asterix
Answer: _________
Question 88:

When we are using heap operations what do we need to do to save the memory?

A. rename the objects
B. delete the objects after processing
C. both rename & delete the objects
D. add the objects
Answer: _________
Question 89:

Which method do we use to append more than one character at a time?

A. append
B. operator+=
C. data
D. both append & operator+=
Answer: _________
Question 90:

How many specifiers are present in access specifiers in class?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 91:

How to access the object in the class?

A. scope resolution operator
B. ternary operator
C. direct member access operator
D. resolution operator
Answer: _________
Question 92:

In case of non-static member functions how many maximum object arguments a unary operator overloaded function can take?

A. 1
B. 2
C. 3
D. 0
Answer: _________
Question 93:

Which keyword is used to make a member function constant in C++?

A. virtual
B. final
C. static
D. const
Answer: _________
Question 94:

What is the difference between a constructor and a normal member function in C++?

A. Constructor is called explicitly when an object is created, while a member function is called automatically
B. Constructor has a return type, while a member function does not
C. Constructor is called automatically when an object is created, while a member function needs to be called explicitly
D. Constructor can be overloaded, while a member function cannot
Answer: _________
Question 95:

What is the purpose of the keyword 'explicit' before a constructor in C++?

A. To specify the return type of the constructor
B. To prevent implicit conversions during object initialization
C. To mark the constructor as static
D. None of the above
Answer: _________
Question 96:

Which keyword is used to prevent inheritance in C++?

A. sealed
B. virtual
C. final
D. override
Answer: _________
Question 97:

What is the access specifier that allows members of a class to be accessed from anywhere in the program in C++?

A. public
B. private
C. protected
D. internal
Answer: _________
Question 98:

What is the difference between a shallow copy and a deep copy in C++?

A. Shallow copy is performed using copy constructors, while deep copy is performed using assignment operators
B. Shallow copy copies only the memory addresses of the objects, while deep copy copies the actual content
C. Shallow copy is faster than deep copy
D. None of the above
Answer: _________
Question 99:

How many parameters does a conversion operator may take?

A. 0
B. 1
C. 2
D. as many as possible
Answer: _________
Question 100:

What is operator overloading in C++?

A. Overriding the operator meaning by the user defined meaning for user defined data type
B. Redefining the way operator works for user defined types
C. Ability to provide the operators with some special meaning for user defined data type
D. All of the mentioned
Answer: _________
Question 101:

Which of the following operator cannot be overloaded?

A. +
B. ?:
C.
D. %
Answer: _________
Question 102:

Which is used to define the member of a class externally?

A. :
B. ::
C. #
D. !!$
Answer: _________
Question 103:

Which operator a pointer object of a class uses to access its data members and member functions?

A. .
B. ->
C. :
D. ::
Answer: _________
Question 104:

Which is the correct example of a unary operator?

A. &
B. ==
C.
D. /
Answer: _________
Question 105:

In case of non-static member functions how many maximum object arguments a binary operator overloaded function can take?

A. 1
B. 2
C. 3
D. 0
Answer: _________
Question 106:

Which type of function is used to destroy objects in C++?

A. Friend function
B. Member function
C. Destructor
D. Constructor
Answer: _________
Question 107:

What is the default access specifier for members of a class in C++?

A. public
B. protected
C. None of the above
D. private
Answer: _________
Question 108:

Which operator is used to access members of an object in C++?

A. Dot operator (.)
B. Arrow operator (->)
C. Double colon (::)
D. Star operator (*)
Answer: _________
Question 109:

What is the difference between a constructor and a destructor in C++?

A. Constructor is called when an object is destroyed, while destructor is called when an object is created
B. Constructor is used to initialize objects, while destructor is used to free resources
C. Constructor is called when an object is created, while destructor is called when an object is destroyed
D. Constructor is used to free resources, while destructor is used to initialize objects
Answer: _________
Question 110:

What is the purpose of the destructor in C++?

A. To define objects within a class
B. To release resources acquired by the object
C. To perform calculations with object data
D. None of the above
Answer: _________
Question 111:

Which keyword is used to declare a class in C++?

A. object
B. typedef
C. class
D. struct
Answer: _________
Question 112:

What is the purpose of the static member variable in C++?

A. To initialize objects of a class
B. To define objects within a class
C. To release resources acquired by the object
D. To maintain common data for all objects
Answer: _________
Question 113:

Which operator is used to access members of a class through a pointer in C++?

A. Arrow operator (->)
B. Dot operator (.)
C. Double colon (::)
D. Star operator (*)
Answer: _________
Question 114:

What is the purpose of using friend functions in C++?

A. To create multiple instances of a class
B. To hide the implementation details of a class
C. To allow access to private and protected members of a class from outside the class
D. To define functions within a class
Answer: _________
Question 115:

Which access specifier allows members of a class to be accessed only by the derived classes in C++?

A. public
B. protected
C. friend
D. None of the above
Answer: _________
Question 116:

What does a class in C++ holds?

A. data
B. functions
C. both data & functions
D. arrays
Answer: _________
Question 117:

What is the size of the heap?

A. 10MB
B. 500MB
C. 1GB
D. Size of the heap memory is limited by the size of the RAM and the swap memory
Answer: _________
Question 118:

Pick the correct statement about string objects in C++.

A. String objects must be terminated by a null character('x00')
B. String objects have a static size
C. String objects have a dynamic size
D. String objects use extra memory than required.
Answer: _________
Question 119:

Why we use the "dynamic_cast" type conversion?

A. result of the type conversion is a valid
B. to be used in low memory
C. result of the type conversion is an invalid
D. it is used for storage
Answer: _________
Question 120:

Which is used to return the number of characters in the string?

A. length
B. size
C. both size & length
D. name
Answer: _________
Question 121:

Pick out the correct syntax of operator conversion.

A. operator float()const
B. operator float()
C. operator const
D. operator const()
Answer: _________
Question 122:

What are the essential operators in c++?

A. +
B. |
C. <=
D. All of the mentioned
Answer: _________
Question 123:

What is the syntax of user-defined data types?

A. typedef ExistingDataType NameByUser
B. typedef NameByUser ExistingDataType
C. def NameByUser ExistingDataType
D. def NameByUser ExistingData
Answer: _________
Question 124:

Which is used to pass the large objects in c++?

A. pass by value
B. pass by reference
C. both pass by value & reference
D. pass by name
Answer: _________
Question 125:

How to stop your program from eating so much ram?

A. Find a way to work with the data one at a time
B. Declare it in program memory, instead of on the stack
C. Use the hard drive, instead of RAM
D. All of the mentioned
Answer: _________
Question 126:

What does a mutable member of a class mean?

A. A member that can never be changed
B. A member that can be updated only if it not a member of constant object
C. A member that can be updated even if it a member of constant object
D. A member that is global throughout the class
Answer: _________
Question 127:

In the case of friend operator overloaded functions how many maximum object arguments a binary operator overloaded function can take?

A. 1
B. 2
C. 3
D. 0
Answer: _________
Question 128:

How many types are there in increment/decrement operator?

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 129:

Which operator is having the highest precedence in c++?

A. array subscript
B. Scope resolution operator
C. static_cast
D. dynamic_cast
Answer: _________
Question 130:

How to unlimit the size of the stack?

A. setrlimit()
B. unlimit()
C. both setrlimit() & unlimit()
D. setflimit()
Answer: _________
Question 131:

What is the term for a function that is declared inside a class but defined outside of it in C++?

A. Inline function
B. Friend function
C. Member function
D. Static function
Answer: _________
Question 132:

What is the process of wrapping data and functions into a single unit called in C++?

A. Inheritance
B. Polymorphism
C. Abstraction
D. Encapsulation
Answer: _________
Question 133:

What is the purpose of the 'this' pointer in C++?

A. Pointer to the previous object instance
B. Pointer to the next object instance
C. Pointer to the current object instance
D. Pointer to the base class object instance
Answer: _________
Question 134:

What is the purpose of using constructors in C++?

A. To hide the implementation details of a class
B. To create multiple instances of a class
C. To initialize the object's data members
D. To destroy the object
Answer: _________
Question 135:

What is a constructor in C++?

A. A function used to destroy objects
B. A function used to create objects
C. A function used to access class members
D. A special member function that initializes objects
Answer: _________
Question 136:

Which keyword is used to create a copy constructor in C++?

A. copy
B. constructor
C. copy_constructor
D. None of the above
Answer: _________
Question 137:

What is the purpose of a copy constructor in C++?

A. To hide the implementation details of a class
B. To destroy objects
C. To initialize an object using another object
D. To create multiple instances of a class
Answer: _________
Question 138:

What happens if a class does not explicitly declare any constructors in C++?

A. A compilation error occurs
B. The class cannot be instantiated
C. The class is initialized with default values
D. A default constructor is provided by the compiler
Answer: _________
Question 139:

What is a destructor in C++?

A. A special member function that destroys objects
B. A function used to create objects
C. A function used to initialize objects
D. A function used to access class members
Answer: _________
Question 140:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

int main(int argc, char const *argv[])
{
string str

cin>>str

cout<<str

return 0

}

A. str
B. Input provided by the user
C. Error
D. Segmentation fault
Answer: _________
Question 141:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

class A
{
mutable int a

public:
int assign(int i) const {
a = i

}
int return_value() const {
return a

}

}

int main(int argc, char const *argv[])
{
A obj

obj.assign(5)

cout<<obj.return_value()

}

A. 5
B. Error
C. Segmentation fault
D. Undefined value
Answer: _________
Question 142:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

int main ()
{
string str ("helloworld.")

cout << str.substr(3).substr(4) << endl

return 0

}

A. world.
B. rld.
C. elloworld.
D. hello
Answer: _________
Question 143:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

int main(int argc, char const *argv[])
{
char str[] = "Hello World"

cout<<str[0]

return 0

}

A. H
B. e
C. Error
D. o
Answer: _________
Question 144:

What will be the output of the following C++ code? #include <iostream>
using namespace std

int main()
{
int a = 0

int b = 10

if ( a && b )
{
cout << "true"<< endl

}
else
{
cout << "false"<< endl

}
return 0

}

A. true
B. false
C. error
D. 10
Answer: _________
Question 145:

What will be the output of the following C++ code? #include <iostream>
using namespace std

int main()
{
typedef int num

num a = 10, b = 15

num c = a + b + a - b

cout << c

return 0

}

A. 20
B. 15
C. 30
D. 25
Answer: _________
Question 146:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

class B
{
int b

public:
B(int i){
b = i

}
}

class C
{
B b

public:
C(int i){
b = B(i)

}
friend void show()

}

void show()
{
C c(10)

cout<<"value of b is: "<<c.b.b<<endl

}

int main(int argc, char const *argv[])
{
show()

return 0

}

A. value of b is: 10
B. value of b is: 12345435
C. error
D. segmentation fault
Answer: _________
Question 147:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

int main ()
{
string str ("nobody does like this")

string key ("nobody")

size_t f

f = str.rfind(key)

if (f != string::npos)
str.replace (f, key.length(), "everybody")

cout << str << endl

return 0

}

A. nobody does like this
B. nobody
C. everybody
D. everybody does like this
Answer: _________
Question 148:

What is the correct syntax of accessing a static member of a Class? ---------------------------
Example class:
class A
{
public:
static int value

}
---------------------------

A. A.value
B. A::value
C. A->value
D. A^value
Answer: _________
Question 149:

What will be the output of the following C++ code? #include <iostream>
using namespace std

class myclass
{
public:
int i

myclass *operator->()
{return this

}
}

int main()
{
myclass ob

ob->i = 10

cout << ob.i << " " << ob->i

return 0

}

A. 10 10
B. 11 11
C. error
D. runtime error
Answer: _________
Question 150:

What happens when objects s1 and s2 are added? string s1 = "Hello"

string s2 = "World"

string s3 = (s1+s2).substr(5)

A. Error because s1+s2 will result into string and no string has substr() function
B. Segmentation fault as two string cannot be added in C++
C. The statements runs perfectly
D. Run-time error
Answer: _________
Question 151:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

class test
{
public:
operator string ()
{
return "Converted"

}
}

int main()
{
test t

string s = t

cout << s << endl

return 0

}

A. converted
B. error
C. run time error
D. convertedconverted
Answer: _________
Question 152:

What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <cstring>
using namespace std

int main()
{
string s('a')

cout<<s

return 0

}

A. a
B. empty string
C. Error
D. Segmentation fault
Answer: _________
Question 153:

What will be the output of the following C++ code? #include <iostream>
using namespace std

class sample

class sample1
{
int width, height

public:
int area ()
{
return (width * height)

}
void convert (sample a)

}

class sample
{
private:
int side

public:
void set_side (int a)
{
side = a

}
friend class sample1

}

void sample1::convert (sample a)
{
width = a.side

height = a.side

}
int main ()
{
sample sqr

sample1 rect

sqr.set_side(6)

rect.convert(sqr)

cout << rect.area()

return 0

}

A. 24
B. 35
C. 16
D. 36
Answer: _________
Question 154:

What will be the output of the following C++ code? #include <iostream>
using namespace std

class Rect
{
int x, y

public:
void set_values (int,int)

int area ()
{
return (x * y)

}
}

void Rect::set_values (int a, int b)
{
x = a

y = b

}
int main ()
{
Rect recta, rectb

recta.set_values (5, 6)

rectb.set_values (7, 6)

cout << "recta area: " << recta.area()

cout << "rectb area: " << rectb.area()

return 0

}

A. recta area: 30 rectb area: 42
B. recta area: 20 rectb area: 34
C. recta area: 30 rectb area: 21
D. recta area: 30 rectb area: 33
Answer: _________
Question 155:

Which access specifier allows members of a class to be accessed only by member functions of the same class and its derived classes in C++?

A. protected
B. public
C. private
D. friend
Answer: _________
Question 156:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class numbers
{
private:
int m_nValues[10]
public:
int& operator[] (const int nValue)
}
int& numbers::operator[](const int nValue)
{
return m_nValues[nValue]
}
int main()
{
numbers N
N[5] = 4
cout << N[5]
return 0
}

A. 5
B. 4
C. 3
D. 6
Answer: _________
Question 157:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
typedef int num
typedef char let
let w = "steve"
num a = 10, b = 15
num c = a + w
cout << c
return 0
}

A. 10steve
B. steve10
C. compile time error
D. compile but not run
Answer: _________
Question 158:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main(int argc, char const *argv[])
{
char str[10]
cin>>str
cout<<str
return 0
}

A. Compiler-time Error
B. Run-time Error
C. Input given by the user
D. Depends on the length of the string entered by the user
Answer: _________
Question 159:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
double arr[] = {5.0, 6.0, 7.0, 8.0}
double *p = (arr+2)
cout << *p << endl
cout << arr << endl
cout << *(arr+3) << endl
cout << *(arr) << endl
cout << *arr+9 << endl
return 0
}

A. 7 0xbf99fc98 8 5 14
B. 7 8 0xbf99fc98 5 14
C. 0xbf99fc98
D. 14
Answer: _________
Question 160:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class B
{
int b
public:
B(){}
B(int i){
b = i
}
int show(){
return b
}
}
class C
{
B b
public:
C(int i){
b = B(i)
}
friend void show(){

C c(10)
cout<<"value of b is: "<<c.b.show()<<endl
}
}
int main(int argc, char const *argv[])
{
C c(1)
c.show()
return 0
}

A. value of b is: 10
B. value of b is: 12345435
C. error
D. segmentation fault
Answer: _________
Question 161:

Which is the correct way of concatenating a character at the end of a string object? way 1:
string s
s = s + 'a'
way 2:
string s
s.push_back('a')

A. 1 only
B. 2 only
C. both of them
D. both are wrong
Answer: _________
Question 162:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main(int argc, char const *argv[])
{
string s1 = "Hello"
string s2 = "World"
string s3 = s1 + " " + s2
cout<<s3
return 0
}

A. Hello World
B. Hello
C. World
D. Error
Answer: _________
Question 163:

Which special character is used to mark the end of class?

A. :
B. #
C. $
Answer: _________
Question 164:

What will be the output of the following C++ code? #include <stdio.h>
#include<iostream>
using namespace std
int main()
{
int x = 5, y = 5
cout << ++x << --y << endl
return 0
}

A. 55
B. 64
C. 46
D. 45
Answer: _________
Question 165:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class base
{
int val1, val2
public:
int get()
{
val1 = 100
val2 = 300
}
friend float mean(base ob)
}
float mean(base ob)
{
return float(ob.val1 + ob.val2) / 2
}
int main()
{
base obj
obj.get()
cout << mean(obj)
return 0
}

A. 200
B. 150
C. 100
D. 300
Answer: _________
Question 166:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class complex
{
int i
int j
public:
complex(int a, int b)
{
i = a
j = b
}
complex operator+(complex c)
{
complex temp
temp.i = this->i + c.i
temp.j = this->j + c.j
return temp
}
void show(){
cout<<"Complex Number: "<<i<<" + i"<<j<<endl
}
}
int main(int argc, char const *argv[])
{
complex c1(1,2)
complex c2(3,4)
complex c3 = c1 + c2
c3.show()
return 0
}

A. 4 + i6
B. 2 + i2
C. Error
D. Segmentation fault
Answer: _________
Question 167:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample1
{
float i, j
}
class sample2
{
int x, y
public:
sample2 (int a, int b)
{
x = a
y = b
}
int result()
{
return x + y
}
}
int main ()
{
sample1 d
sample2 * padd
padd = (sample2*) &d
cout<< padd->result()
return 0
}

A. 20
B. runtime error
C. random number
D. runtime error or random number
Answer: _________
Question 168:

What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <cstring>
using namespace std
int main(int argc, char const *argv[])
{
const char *a = "Hellox00World"
cout<<a
return 0
}

A. Hello World
B. Hello
C. World
D. Error
Answer: _________
Question 169:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
static int a
public:
void change(int i){
a = i
}
void value_of_a(){
cout<<a
}
}
int A::a = 5
int main(int argc, char const *argv[])
{
A a1 = A()
A a2 = A()
A a3 = A()
a1.change(10)
a1.value_of_a()
a2.value_of_a()
a3.value_of_a()
return 0
}

A. 1055
B. 555
C. 101010
D. 51010
Answer: _________
Question 170:

What will be the output of the following C++ code? #include <iostream>
#include <complex>
using namespace std
int main ()
{
complex<double> mycomplex (20.0, 2.0)
cout << imag(mycomplex) << endl
return 0
}

A. 2
B. 20
C. 40
D. 30
Answer: _________
Question 171:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class Integer
{
int i
public:
Integer(int ii) : i(ii) {}
const Integer
operator+(const Integer& rv) const
{
cout << "operator+" << endl
return Integer(i + rv.i)
}
Integer&
operator+=(const Integer& rv)
{
cout << "operator+=" << endl
i += rv.i
return *this
}
}
int main()
{
int i = 1, j = 2, k = 3
k += i + j
Integer ii(1), jj(2), kk(3)
kk += ii + jj
}

A. operator+ operator+=
B. operator+= operator+
C. operator+ operator+
D. operator+ operator=
Answer: _________
Question 172:

What will be the output of the following C++ code? #include <iostream>
using namespace std
ostream & operator<<(ostream & i, int n)
{
return i
}
int main()
{
cout << 5 << endl
cin.get()
return 0
}

A. 5
B. 6
C. error
D. runtime error
Answer: _________
Question 173:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class Box{
int capacity
bool operator<(Box b){
return this->capacity < b.capacity ? true : false
}
public:
Box(){}
Box(double capacity){
this->capacity = capacity
}
}
int main(int argc, char const *argv[])
{
Box b1(10)
Box b2 = Box(14)
if(b1 < b2){
cout<<"Box 2 has large capacity."
}
else{
cout<<"Box 1 has large capacity."
}
return 0
}

A. Error
B. Segmentation fault
C. Box 2 has large capacity
D. No output
Answer: _________
Question 174:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main ()
{
int a, b
a = 10
b = 4
a = b
b = 7
cout << "a:"
cout << a
cout << " b:"
cout << b
return 0
}

A. a:4 b:7
B. a:10 b:4
C. a:4 b:10
D. a:4 b:6
Answer: _________
Question 175:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
std::string str ("Example.")
str.back() = '!'
std::cout << str << endl
return 0
}

A. Example.!
B. Example.
C. Example!
D. Example!.
Answer: _________
Question 176:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class rect
{
int x, y
public:
void val (int, int)
int area ()
{
return (x * y)
}
}
void rect::val (int a, int b)
{
x = a
y = b
}
int main ()
{
rect rect
rect.val (3, 4)
cout << "rect area: " << rect.area()
return 0
}

A. rect area: 24
B. rect area: 12
C. compile error because rect is as used as class name and variable name in line #20
D. rect area: 56
Answer: _________
Question 177:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class Box
{
double length
double breadth
double height
public:
double getVolume(void)
{
return length * breadth * height
}
void setLength( double len )
{
length = len
}
void setBreadth( double bre )
{
breadth = bre
}
void setHeight( double hei )
{
height = hei
}
Box operator+(const Box& b)
{
Box box
box.length = this->length + b.length
box.breadth = this->breadth + b.breadth
box.height = this->height + b.height
return box
}
}
int main( )
{
Box Box1
Box Box2
Box Box3
double volume = 0.0
Box1.setLength(6.0)
Box1.setBreadth(7.0)
Box1.setHeight(5.0)
Box2.setLength(12.0)
Box2.setBreadth(13.0)
Box2.setHeight(10.0)
volume = Box1.getVolume()
cout << "Volume of Box1 : " << volume <<endl
volume = Box2.getVolume()
cout << "Volume of Box2 : " << volume <<endl
Box3 = Box1 + Box2
volume = Box3.getVolume()
cout << "Volume of Box3 : " << volume <<endl
return 0
}

A. Volume of Box1 : 210 Volume of Box2 : 1560 Volume of Box3 : 5400
B. Volume of Box1 : 200 Volume of Box2 : 1560 Volume of Box3 : 5400
C. Volume of Box1 : 210 Volume of Box2 : 1550 Volume of Box3 : 5400
D. Volume of Box1 : 200 Volume of Box2 : 1000 Volume of Box3 : 5260
Answer: _________
Question 178:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
string str ("Ubuntu")
cout << str.capacity()
cout << str.max_size()
return 0
}

A. 61073741820
B. 51073741820
C. 6 and max size depends on compiler
D. 15 9223372036854770000
Answer: _________
Question 179:

What will be the output of the following C++ code? #include <iostream>
using namespace std
void duplicate (int& a, int& b, int& c)
{
a *= 2
b *= 2
c *= 2
}
int main ()
{
int x = 1, y = 3, z = 7
duplicate (x, y, z)
cout << x << y << z
return 0
}

A. 1468
B. 2812
C. 2614
D. 2713
Answer: _________
Question 180:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int a = 20
int b = 10
int c = 15
int d = 5
int e
e = a + b * c / d
cout << e << endl
return 0
}

A. 50
B. 60
C. 70
D. 90
Answer: _________
Question 181:

What will be the output of the following C++ code? #include <iostream>
#include <cstring>
using namespace std
int main ()
{
char str1[10] = "Hello"
char str2[10] = "World"
char str3[10]
int len
strcpy( str3, str1)
strcat( str1, str2)
len = strlen(str1)
cout << len << endl
return 0
}

A. 5
B. 55
C. 11
D. 10
Answer: _________
Question 182:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class Box{
int capacity
public:
Box(){}
Box(double capacity){
this->capacity = capacity
}
bool operator<(Box b){
return b.capacity < this->capacity? true : false
}
}
int main(int argc, char const *argv[])
{
Box b1(10)
Box b2 = Box(14)
if(b1 < b2){
cout<<"B1's capacity is small"
}
else{
cout<<"B2's capacity is small"
}
return 0
}

A. B1's capacity is small
B. B2's capacity is small
C. Error
D. Segmentation fault
Answer: _________
Question 183:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class complex
{
int i
int j
public:
complex(){}
complex(int a, int b)
{
i = a
j = b
}
complex operator+(complex c)
{
complex temp
temp.i = this->i + c.i
temp.j = this->j + c.j
return temp
}
void operator+(complex c)
{
complex temp
temp.i = this->i + c.i
temp.j = this->j + c.j
temp.show_poss()
}
void show(){
cout<<"Complex Number: "<<i<<" + i"<<j<<endl
}
void show_poss(){
cout<<"Your result after addition will be: "<<i<<" + i"<<j<<endl
}
}
int main(int argc, char const *argv[])
{
complex c1(1,2)
complex c2(3,4)
c1 + c2
return 0
}

A. Complex Number: 4 + i6
B. Complex Number: 2 + i2
C. Error
D. Segmentation fault
Answer: _________
Question 184:

What will be the output of the following C++ code? #include <stdio.h>
#include<iostream>
using namespace std
int main()
{
int x = 5, y = 5, z
x = ++x
y = --y
z = x++ + y--
cout << z
return 0
}

A. 10
B. 11
C. 9
D. 12
Answer: _________
Question 185:

What will be the output of the following C++ code? #include <stdio.h>
#include<iostream>
using namespace std
int main()
{
int num1 = 5
int num2 = 3
int num3 = 2
num1 = num2++
num2 = --num3
cout << num1 << num2 << num3
return 0
}

A. 532
B. 235
C. 312
D. 311
Answer: _________
Question 186:

Which of the following is correct way of concatenating two string objects in C++? way 1:
string s1 = "hello"
string s2 = "world"
string s3 = s1 + s2
way 2:
string s1 = "hello"
string s2 = "world"
string s3 = s1.append(s2)
way 3:
string s1 = "hello"
string s2 = "world"
string s3 = strcat(s1,s2)

A. 1 and 2
B. 2 and 3
C. 1 and 3
D. 1, 2 and 3
Answer: _________
Question 187:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample
{
private:
int a, b
public:
void test()
{
a = 100
b = 200
}
friend int compute(sample e1)
}
int compute(sample e1)
{
return int(e1.a + e1.b) - 5
}
int main()
{
sample e
e.test()
cout << compute(e)
return 0
}

A. 100
B. 200
C. 300
D. 295
Answer: _________
Question 188:

What will be the output of the following C++ code? #include <iostream>
#include <complex>
using namespace std
int main()
{
complex<double> c1(4.0,3.0)
cout << "c1: " << c1
complex<float> c2(polar(5.0,0.75))
cout << c1 + complex<double>(c2.real(),c2.imag())
return 0
}

A. c1: (4,3)(7.65844,6.40819)
B. c1: (4,3)(7,6)
C. both c1: (4,3)(7.65844,6.40819) & c1: (4,3)(7,6)
D. c1: (5,3)(7,6)
Answer: _________
Question 189:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int x
int *p
x = 5
p = &x
cout << *p
return 0
}

A. 5
B. 10
C. memory address
D. 15
Answer: _________
Question 190:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int i
enum month
{
JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC
}
for (i = JAN
i <= DEC
i++)
cout << i
return 0
}

A. 012345678910
B. 0123456789
C. 01234567891011
D. 01234567891011122
Answer: _________
Question 191:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int a, b
int* c
c = &a
a = 200
b = 200
*c = 100
b = *c
cout << *c << " " << b
return 0
}

A. 100 200
B. 100 0
C. 200 200
D. 100 100
Answer: _________
Question 192:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
static int a
public:
void change(int i){
a = i
}
void value_of_a(){
cout<<a
}
}
int main(int argc, char const *argv[])
{
A a1 = A()
a1.change(5)
a1.value_of_a()
return 0
}

A. 5
B. Garbage value
C. Error
D. Segmentation fault
Answer: _________
Question 193:

What will be the output of the following C++ code if the string entered by the user is "Hello World"? #include <iostream>
#include <string>
using namespace std
int main(int argc, char const *argv[])
{
string str
cin>>str
cout<<str
return 0
}

A. Hello World
B. Hello
C. World
D. Error
Answer: _________
Question 194:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
double a = 21.09399
float b = 10.20
int c
c = (int) a
cout << c
c = (int) b
cout << c
return 0
}

A. 2110
B. 1210
C. 21
D. 121
Answer: _________
Question 195:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
string str ("microsoft")
string::reverse_iterator r
for (r = str.rbegin()
r < str.rend()
r++ )
cout << *r
return 0
}

A. microsoft
B. micro
C. tfosorcim
D. tfos
Answer: _________
Question 196:

Given the following C++ code. How would you define the < operator for Box class so that when boxes b1 and b2 are compared in if block the program gives correct result? #include <iostream>
#include <string>
using namespace std
class Box
{
int capacity
public:
Box(){}
Box(double capacity){
this->capacity = capacity
}
}
int main(int argc, char const *argv[])
{
Box b1(10)
Box b2 = Box(14)
if(b1 < b2){
cout<<"Box 2 has large capacity."
}
else{
cout<<"Box 1 has large capacity."
}
return 0
}

A. bool operator<(Box b) { return this->capacity < b.capacity ? true : false }
B. bool operator<(Box b) { return this->capacity > b.capacity ? true : false }
C. bool operator<(Box b) { return b1 > b2 ? true : false }
D. bool operator<(Box b) { return this < b ? true : false }
Answer: _________
Question 197:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample
{
public:
sample(int i) : m_i(i) { }
public:
int operator()(int i = 0) const
{
return m_i + i
}
operator int () const
{
return m_i
}
private:
int m_i
friend int g(const sample&)
}
int f(char c)
{
return c
}
int main()
{
sample f(2)
cout << f(2)
return 0
}

A. 3
B. 4
C. 5
D. 6
Answer: _________
Question 198:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
string str ("example.")
str.front() = 'E'
cout << str << endl
return 0
}

A. Example
B. Example.
C. example
D. example.
Answer: _________
Question 199:

What will be the output of the following C++ code? #include <iostream>
#include <complex>
using namespace std
int main()
{
complex<int> i(2, 3)
i = i * 6 / 3
cout << i
return 0
}

A. (4, 6)
B. (2, 3)
C. (6, 12)
D. (6, 15)
Answer: _________
Question 200:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample
{
public:
sample()
{
cout << "X::X()" << endl
}
sample( sample const & )
{
cout << "X::X( X const & )" << endl
}
sample& operator=( sample const & )
{
cout << "X::operator=(X const &)" << endl
}
}
sample f()
{
sample tmp
return tmp
}
int main()
{
sample x = f()
return 0
}

A. X::operator=(X const &)
B. X::X( X const & )
C. X::X()
D. X::operator
Answer: _________
Question 201:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main ()
{
int a, b, c
a = 2
b = 7
c = (a > b) ? a : b
cout << c
return 0
}

A. 2
B. 7
C. 9
D. 14
Answer: _________
Question 202:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class Distance
{
private:
int feet
int inches
public:
Distance()
{
feet = 0
inches = 0
}
Distance(int f, int i)
{
feet = f
inches = i
}
Distance operator()(int a, int b, int c)
{
Distance D
D.feet = a + c + 10
D.inches = b + c + 100
return D
}
void displayDistance()
{
cout << feet << inches << endl
}
}
int main()
{
Distance D1(11, 10), D2
cout << "First Distance : "
D1.displayDistance()
D2 = D1(10, 10, 10)
cout << "Second Distance :"
D2.displayDistance()
return 0
}

A. First Distance : 1110 Second Distance :30120
B. First Distance : 110 Second Distance :3020
C. First Distance : 1115 Second Distance :30125
D. First Distance : 100 Second Distance :30120
Answer: _________
Question 203:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
int a = 5
public:
void change(int i){
a = i
}
static void value_of_a(){
cout<<a
}
}
int main(int argc, char const *argv[])
{
A a1 = A()
a1.change(10)
a1.value_of_a()
return 0
}

A. 10
B. Error
C. Segmentation Fault
D. 5
Answer: _________
Question 204:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class Box
{
int capacity
public:
Box(int cap){
capacity = cap
}
friend void show()
}
void Box::show()
{
Box b(10)
cout<<"Value of capacity is: "<<b.capacity<<endl
}

int main(int argc, char const *argv[])
{
show()
return 0
}

A. Value of capacity is: 10
B. Value of capacity is: 100
C. Error
D. Segmentation fault
Answer: _________
Question 205:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
string str ("steve jobs is legend")
string::iterator it
str.erase (str.begin()+ 5, str.end()-7)
cout << str << endl
return 0
}

A. jobs is
B. steve legend
C. steve
D. steve jobs is
Answer: _________
Question 206:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class A
{
public:
int x
A(int n = 0) : x(n) {}
int& operator[](int n)
{
cout << "0"
return x
}
int operator[](int n) const
{
cout << "1"
return x
}
}
void foo(const A& a)
{
int z = a[2]
}
int main()
{
A a(7)
a[3] = 8
int z = a[2]
foo(a)
return 0
}

A. 110
B. 111
C. 011
D. 001
Answer: _________
Question 207:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class Box
{
double width
public:
friend void printWidth( Box box )
void setWidth( double wid )
}
void Box::setWidth( double wid )
{
width = wid
}
void printWidth( Box box )
{
box.width = box.width * 2
cout << "Width of box : " << box.width << endl
}
int main( )
{
Box box
box.setWidth(10.0)
printWidth( box )
return 0
}

A. 40
B. 5
C. 10
D. 20
Answer: _________
Question 208:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class Complex
{
private:
float real
float imag
public:
Complex():real(0), imag(0){}
Complex operator ()(float re, float im)
{
real += re
imag += im
return *this
}
Complex operator() (float re)
{
real += re
return *this
}
void display()
{
cout << "(" << real << "," << imag << ")" << endl
}
}
int main()
{
Complex c1, c2
c2 = c1(3.2, 5.3)
c1(6.5, 2.7)
c2(1.9)
cout << "c2="
c1.display()
cout << "c2="
c2.display()
return 0
}

A. c2=(9.7,8) c2=(5.1,5.3)
B. c2=(9,8) c2=(5,5)
C. c2=(4.7,8) c2=(2.1,5.3)
D. c2=(5.7,8) c2=(5.1,5.6)
Answer: _________
Question 209:

What will be the output of the following C++ code? #include <iostream>
#include <complex>
using namespace std
int main()
{
complex<double> c1(4.0, 3.0)
complex<float> c2(polar(5.0, 0.75))
cout << (c1 += sqrt(c1)) << endl
return 0
}

A. (4.0, 3.0)
B. (6.12132, 3.70711)
C. (5.0, 0.75)
D. (5.0, 3.75)
Answer: _________
Question 210:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class Box
{
int capacity
Box(){}
Box(double capacity){
this->capacity = capacity
}
}
int main(int argc, char const *argv[])
{
Box b1(10)
Box b2 = Box(14)
return 0
}

A. Error
B. Segmentation fault
C. 4
D. No output
Answer: _________
Question 211:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class B
{
int b
public:
B(){}
B(int i){
b = i
}
int show(){
return b
}
}
class C
{
B b
public:
C(int i){
b = B(i)
}
friend void show(){

C c(10)
cout<<"value of b is: "<<c.b.show()<<endl
}
}
int main(int argc, char const *argv[])
{
show()
return 0
}

A. value of b is: 10
B. value of b is: 12345435
C. error
D. segmentation fault
Answer: _________
Question 212:

Give the function prototype of the operator function which we need to define in this program so that the program has no errors. #include <iostream>
#include <string>
using namespace std
class Box{
int capacity
public:
Box(){}
Box(double capacity){
this->capacity = capacity
}
}
int main(int argc, char const *argv[])
{
Box b1(10)
Box b2 = Box(14)
if(b1 == b2){
cout<<"Equal"
}
else{
cout<<"Not Equal"
}
return 0
}

A. bool operator==()
B. bool operator==(Box b){}
C. bool operator==(Box b)
D. Box operator==()
Answer: _________
Question 213:

What will be the output of the following C++ code? #include <iostream>
#include <cmath>
using namespace std
class Complex
{
private:
double real
double imag
public:
Complex(double r = 0.0, double i = 0.0) : real(r), imag(i)
{}
double mag()
{
return getMag()
}
operator double ()
{
return getMag()
}
private:
double getMag()
{
return sqrt(real * real + imag * imag)
}
}
int main()
{
Complex com(3.0, 4.0)
cout << com.mag()
cout << com
return 0
}

A. 5 5
B. 4 5
C. 6 6
D. 7 5
Answer: _________
Question 214:

What is the associativity of add(+)
?

A. right to left
B. left to right
C. right to left & left to right
D. top to bottom
Answer: _________
Question 215:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class number
{
int i
public:
int geti()
void puti(int j)
}
int number::geti()
{
return i
}
void number::puti(int j)
{
i = j
}
int main()
{
number s
s.puti(10)
cout << s.geti( )
return 0
}

A. 10
B. 11
C. 20
D. 22
Answer: _________
Question 216:

How many member functions are there in this C++ class excluding constructors and destructors? class Box
{
int capacity
public:
void print()
friend void show()
bool compare()
friend bool lost()
}

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 217:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
string str = "HelloWorld!"
cout<<str.capacity()
cout<<str.size()
return 0
}

A. 1511
B. 1111
C. 1115
D. 010
Answer: _________
Question 218:

What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <cstring>
using namespace std
int main(int argc, char const *argv[])
{
string s("a")
cout<<s
return 0
}

A. a
B. empty string
C. Error
D. Segmentation fault
Answer: _________
Question 219:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main(int argc, char const *argv[])
{
char s1[6] = "Hello"
char s2[6] = "World"
char s3[12] = s1 + " " + s2
cout<<s3
return 0
}

A. Hello World
B. Hello
C. World
D. Error
Answer: _________
Question 220:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
static int a
public:
A()
{
cout<<"Object of A is created
"
}
void show()
{
a++
cout<<"a: "<<a<<endl
}
}
class B
{
public:
}
int main(int argc, char const *argv[])
{
A a1, a2
A a3 = a1 + a2
return 0
}

A. Runs perfectly
B. Run-time Error
C. Segmentation fault
D. Compile-time Error
Answer: _________
Question 221:

#include <iostream>
using namespace std
class three_d
{
int x, y, z
public:
three_d() { x = y = z = 0
}
three_d(int i, int j, int k) { x = i
y = j
z = k
}
three_d operator()(three_d obj)
three_d operator()(int a, int b, int c)
friend ostream &operator<<(ostream &strm, three_d op)
}
three_d three_d::operator()(three_d obj)
{
three_d temp
temp.x = (x + obj.x) / 2
temp.y = (y + obj.y) / 2
temp.z = (z + obj.z) / 2
return temp
}
three_d three_d::operator()(int a, int b, int c)
{
three_d temp
temp.x = x + a
temp.y = y + b
temp.z = z + c
return temp
}
ostream &operator<<(ostream &strm, three_d op) {
strm << op.x << ", " << op.y << ", " << op.z << endl
return strm
}
int main()
{
three_d objA(1, 2, 3), objB(10, 10, 10), objC
objC = objA(objB(100, 200, 300))
cout << objC
return 0
}

A. 55, 106, 156
B. 55, 106
C. 55, 106, 159
D. 55, 106, 158
Answer: _________
Question 222:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample
{
private:
int* i
int j
public:
sample (int j)
~sample ()
int& operator [] (int n)
}
int& sample::operator [] (int n)
{
return i[n]
}
sample::sample (int j)
{
i = new int [j]
j = j
}
sample::~sample ()
{
delete [] i
}
int main ()
{
sample m (5)
m [0] = 25
m [1] = 20
m [2] = 15
m [3] = 10
m [4] = 5
for (int n = 0
n < 5
++ n)
cout << m [n]
return 0
}

A. 252015105
B. 510152025
C. 51015
D. 51015210
Answer: _________
Question 223:

What will be the output of the following C++ code? #include <stdio.h>
#include<iostream>
using namespace std
int main()
{
int x = 5, y = 5, z
x = ++x
y = --y
z = x + ++x
cout << z
return 0
}

A. 11
B. 12
C. 13
D. 14
Answer: _________
Question 224:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class B
{
int b
public:
B(){}
B(int i){
b = i
}
int show(){
return b
}
}
class C
{
B b
public:
C(int i){
b = B(i)
}
friend void show()
}
void show()
{
C c(10)
cout<<"value of b is: "<<c.b.show()<<endl
}

int main(int argc, char const *argv[])
{
show()
return 0
}

A. value of b is: 10
B. value of b is: 12345435
C. error
D. segmentation fault
Answer: _________
Question 225:

What will be the output of the following C++ code? #include using namespace std
class CDummy
{
public:
int isitme (CDummy& param)
}
int CDummy::isitme (CDummy& param)
{
if (&param == this)
return true
else
return false
}
int main ()
{
CDummy a
CDummy *b = &a
if (b->isitme(a))
{
cout << "execute"
}
else
{
cout<<"not execute"
}
return 0
}

A. execute
B. not execute
C. error
D. both execute & not execute
Answer: _________
Question 226:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
static int a
public:
void show()
{
a++
cout<<"a: "<<a<<endl
}
}
int A::a = 5
int main(int argc, char const *argv[])
{
A a
return 0
}

A. Error as a private member a is referenced outside the class
B. Segmentation fault
C. No output
D. Program compiles successfully but gives run-time error
Answer: _________
Question 227:

Which operator should be overloaded in the following code to make the program error free? #include <iostream>
#include <string>
using namespace std
class Box{
int capacity
public:
Box(){}
Box(double capacity){
this->capacity = capacity
}
}
int main(int argc, char const *argv[])
{
Box b1(10)
Box b2 = Box(14)
if(b1 == b2){
cout<<"Equal"
}
else{
cout<<"Not Equal"
}
return 0
}

A. +
B. ==
C. =
D. ()
Answer: _________
Question 228:

Which of the following is a valid class declaration?

A. class A { int x }
B. class B { }
C. public class A { }
D. object A { int x }
Answer: _________
Question 229:

What will be the output of the following C++ code? #include <iostream>
#include <complex>
using namespace std
int main()
{
complex<double> c1(4.0, 16.0), c2
c2 = pow(c1, 2.0)
cout << c2
return 0
}

A. (-240, 128)
B. (240, 128)
C. (240, 120)
D. (240, -122)
Answer: _________
Question 230:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class S
{
int m
public:
#define MAC(S::m)
}
int main(int argc, char const *argv[])
{
cout<<"Hello World"
return 0
}

A. Hello World
B. Error
C. Segmentation Fault
D. Blank Space
Answer: _________
Question 231:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main ()
{
int a
int * ptr_b
int ** ptr_c
a = 1
ptr_b = &a
ptr_c = &ptr_b
cout << a << "
"
cout << *ptr_b << "
"
cout << *ptr_c << "
"
cout << **ptr_c << "
"
return 0
}

A. 1 1 0xbffc9924 1
B. 1 1 1 0xbffc9924
C. 1 0xbffc9924 1 1
D. 0xbffc9924
Answer: _________
Question 232:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample
{
private:
int var
public:
void input()
{
cout << var
}
void output()
{
cout << "Variable entered is "
cout << var << "
"
}
}
int main()
{
sample object
object.input()
object.output()
object.var()
return 0
}

A. Enter an integer 5 Variable entered is 5
B. Runtime error
C. Error
D. Enter an integer 7 Variable entered is 7
Answer: _________
Question 233:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class Box
{
int capacity
public:
Box(int cap){
capacity = cap
}

friend void show()
}
void show()
{
Box b(10)
cout<<"Value of capacity is: "<<b.capacity<<endl
}

int main(int argc, char const *argv[])
{
show()
return 0
}

A. Value of capacity is: 10
B. Value of capacity is: 100
C. Error
D. Segmentation fault
Answer: _________
Question 234:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
int a
public:
int assign(int i) const {
a = i
}
int return_value() const {
return a
}
}
int main(int argc, char const *argv[])
{
A obj
obj.assign(5)
cout<<obj.return_value()
}

A. 5
B. 10
C. Error
D. Segmentation fault
Answer: _________
Question 235:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
string str ("Microsoft")
for (size_t i = 0
i < str.length()
)
{
cout << str.at(i-1)
}
return 0
}

A. M
B. Microsoft
C. Micro
D. runtime error
Answer: _________
Question 236:

What will be the output of the following C++ code? #include <stdio.h>
#include<iostream>
using namespace std
int main()
{
int a = 21
int c
c = a++
cout << c
return 0
}

A. 21
B. 22
C. 23
D. 20
Answer: _________
Question 237:

What will be the output of the following C++ code? #include <iostream>
using namespace std
const int SIZE = 10
class safe
{
private:
int arr[SIZE]
public:
safe()
{
register int i
for (i = 0
i < SIZE
i++)
{
arr[i] = i
}
}
int &operator[](int i)
{
if (i > SIZE)
{
cout << "Index out of bounds" <<endl
return arr[0]
}
return arr[i]
}
}
int main()
{
safe A
cout << A[5]
cout << A[12]
return 0
}

A. 5Index out of bounds 0
B. 40
C. 50
D. 51
Answer: _________
Question 238:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample
{
public:
int x, y
sample() {}
sample(int, int)
sample operator + (sample)
}
sample::sample (int a, int b)
{
x = a
y = b
}
sample sample::operator+ (sample param)
{
sample temp
temp.x = x + param.x
temp.y = y + param.y
return (temp)
}
int main ()
{
sample a (4,1)
sample b (3,2)
sample c
c = a + b
cout << c.x << "," << c.y
return 0
}

A. 5, 5
B. 7, 3
C. 3, 7
D. 3, 5
Answer: _________
Question 239:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
static int a
public:
void show()
{
a++
cout<<"a: "<<a<<endl
}
void operator.()
{
cout<<"Objects are added
"
}
}
class B
{
public:
}
int main(int argc, char const *argv[])
{
A a1, a2
return 0
}

A. Run-time Error
B. Runs perfectly
C. Segmentation fault
D. Compile-time error
Answer: _________
Question 240:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int x = 9
int* p = &x
cout << sizeof(p)
return 0
}

A. 4
B. 2
C. Depends on compiler
D. 8
Answer: _________
Question 241:

What will be the output of the following C++ code? #include <iostream>
using namespace std
const int limit = 4
class safearray
{
private:
int arr[limit]
public:
int& operator [](int n)
{
if (n == limit - 1)
{
int temp
for (int i = 0
i < limit
i++)
{
if (arr[n + 1] > arr[n])
{
temp = arr[n]
arr[n] = arr[n + 1]
arr[n + 1] = temp
}
}
}
return arr[n]
}
}
int main()
{
safearray sa1
for(int j = 0
j < limit
j++)
sa1[j] = j*10
for(int j = 0
j < limit
j++)
{
int temp = sa1[j]
cout << "Element " << j << " is " << temp
}
return 0
}

A. 0102030
B. 1020300
C. 3020100
D. error
Answer: _________
Question 242:

What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class complex
{
int i
int j
public:
complex(){}
complex(int a, int b)
{
i = a
j = b
}
complex operator+(complex c)
{
complex temp
temp.i = this->i + c.i
temp.j = this->j + c.j
return temp
}
void show(){
cout<<"Complex Number: "<<i<<" + i"<<j<<endl
}
}
int main(int argc, char const *argv[])
{
complex c1(1,2)
complex c2(3,4)
complex c3 = c1 + c2
c3.show()
return 0
}

A. Complex Number: 4 + i6
B. Complex Number: 2 + i2
C. Error
D. Segmentation fault
Answer: _________
Question 243:

What will be the output of the following C++ code? #include <iostream>
#include <complex>
using namespace std
int main()
{
complex<double> c_double(2, 3)
complex<int> c_int(4, 5)
c_double *= 2
c_double = c_int
cout << c_double
return 0
}

A. (2, 3)
B. (4, 5)
C. (8, 15)
D. (8, 10)
Answer: _________
Question 244:

What will be the output of the following C++ code? #include <iostream>
using namespace std
int operate (int a, int b)
{
return (a * b)
}
float operate (float a, float b)
{
return (a / b)
}
int main ()
{
int x = 5, y = 2
float n = 5.0, m = 2.0
cout << operate (x, y)
cout << operate (n, m)
return 0
}

A. 119
B. 102.5
C. 123.4
D. 128.4
Answer: _________
Question 245:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class Box
{
public :
double length
double breadth
double height
}
int main( )
{
Box Box1
double volume
Box1.height = 5
Box1.length = 6
Box1.breadth = 7.1
volume = Box1.height * Box1.length * Box1.breadth
cout << "Volume of Box1 : " << volume <<endl
return 0
}

A. 210
B. 213
C. 215
D. 217
Answer: _________
Question 246:

What will be the output of the following C++ code? #include <iostream>
using namespace std
class sample
{
int width, height
public:
void set_values (int, int)
int area () {return (width * height)
}
friend sample duplicate (sample)
}
void sample::set_values (int a, int b)
{
width = a
height = b
}
sample duplicate (sample rectparam)
{
sample rectres
rectres.width = rectparam.width * 2
rectres.height = rectparam.height * 2
return (rectres)
}
int main ()
{
sample rect, rectb
rect.set_values (2, 3)
rectb = duplicate (rect)
cout << rectb.area()
return 0
}

A. 20
B. 16
C. 24
D. 18
Answer: _________

Answer Key

1: D
2: B
3: C
4: A
5: B
6: D
7: C
8: D
9: B
10: C
11: D
12: B
13: A
14: D
15: C
16: B
17: A
18: B
19: A
20: B
21: D
22: B
23: D
24: D
25: B
26: A
27: B
28: B
29: D
30: A
31: B
32: D
33: A, E, I, M, Q
34: A
35: D
36: C
37: D
38: C
39: A
40: C
41: B
42: C
43: D
44: D
45: C
46: D
47: D
48: D
49: A
50: C, F
51: A
52: A
53: B
54: B
55: B
56: C
57: A
58: C
59: C
60: D
61: B
62: B
63: C
64: C
65: C
66: A
67: D
68: A
69: B
70: C
71: B
72: B
73: B
74: A
75: A
76: B
77: A
78: B
79: D
80: B
81: D
82: C
83: D
84: A
85: A
86: B
87: C
88: B
89: D
90: C
91: C
92: D
93: D
94: C
95: B
96: C
97: A
98: B
99: A
100: D
101: B
102: B
103: B
104: C
105: A
106: C
107: D
108: A
109: C
110: B
111: C
112: D
113: A
114: C
115: B
116: C
117: D
118: C
119: A
120: C
121: A
122: D
123: A
124: B
125: D
126: C
127: B
128: B
129: B
130: A
131: C
132: D
133: C
134: C
135: D
136: D
137: C
138: D
139: A
140: B
141: A
142: B
143: A
144: B
145: A
146: C
147: D
148: B
149: A
150: C
151: A
152: C
153: D
154: A
155: A
Solution: Access specifiers in C++ determine the visibility and accessibility of class members. The protected access specifier allows members of a class to be accessed by: 1. Member functions of the same class 2. Member functions of its derived (child) classes This makes protected different from private , which restricts access only to the class itself, and from public , which allows access from anywhere. Now let’s see why the other options are incorrect: Option B: public — Members are accessible from anywhere in the program , which is more permissive than required by the question. Option C: private — Members are accessible only within the same class , not by derived classes, so this is too restrictive. Option D: friend — friend is not an access specifier

it is a keyword used to allow a specific external function or class to access private or protected members of another class. It doesn’t define a general access level. Conclusion: The protected access specifier is the one that allows class members to be accessed within the same class and its derived classes. Hence, the correct answer is Option A: protected .
156: B
157: C
158: D
159: A
160: C
161: C
162: A
163: N/A
164: B
165: A
166: C
167: D
168: B
169: C
170: A
171: A
172: C
173: A
174: A
175: C
176: B
177: A
178: D
179: C
180: A
181: D
182: B
183: C
184: A
185: D
186: A
187: D
188: A
189: A
190: A
191: D
192: C
193: B
194: A
195: C
196: A
197: B
198: B
199: A
200: C
201: B
202: A
203: B
204: C
205: B
206: D
207: D
208: A
209: B
210: A
211: C
212: C
213: A
214: B
215: A
216: B
217: A
218: A
219: D
220: D
221: A
222: A
223: D
224: A
225: A
226: C
227: B
228: A
229: A
230: B
231: A
232: C
233: A
234: C
235: D
236: A
237: A
238: B
239: D
240: C
241: A
242: A
243: B
244: B
245: B
246: C