Test Series - cpp

Test Number 31/102

Q: 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
Solution: Fundamental/Atomic data type includes int, char, float, double and void. Derived data type includes arrays, pointers, references, function and constants. User defined derived data type includes class, structure, union and enumeration.
Q: Which operator a pointer object of a class uses to access its data members and member functions?
A. .
B. ->
C. :
D. ::
Solution: ->(arrow operator) is used by a pointer object to access members of its class.
Q: 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
Solution: In Classes objects are self-referenced using this pointer inside the member functions. for example this->value to access the data member value of that object.
Q: 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
Solution: Mutable members are those which can be updated even if it a member of a constant object. You can change their value even from a constant member function of that class.
Q: 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
Solution: Inline are functions that are expanded when it is called. The whole code of the inline function gets inserted/substituted at the point of call. In this, they help in reducing the function call overheads. Also they save overhead of a return call from a function. Inline functions are generally kept small.
Q: Inline functions are avoided when ____________________________
A. function contains static variables
B. function have recursive calls
C. function have loops
D. all of the mentioned
Solution: Inline functions are avoided in all the above cases as whole inline code is copied to the point of call so compiler avoids to make large functions as inline. Even if you yourself mention inline but the function is large compiler ignores your request of inline and treats that function as a normal function.
Q: Pick the correct statement.
A. Macros and inline functions are same thing
B. Macros looks like function calls but they are actually not
C. Inline functions looks like function but they are not
D. Inline function are always large
Solution: Macros in C++ looks like function calls but actually they are not function calls.
Q: 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
Solution: All the functions defined inside the class or functions having inline keyword before them are inline functions of a class provided they are small and simple otherwise compiler ignores the request of inline.
Q: Which keyword is used to define the user defined data types?
A. def
B. union
C. typedef
D. type
Solution: Typedef is used to define user defined datatypes.
eg:
typedef int INT;
INT a;
here INT is used defined data type.
Q: 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
Solution: By using typedef, we can create a type of pre-existing type only not our own type of data.

You Have Score    /10