Miscellaneous C++

Description

C++ Quiz on Miscellaneous C++, created by PathaPadha Support on 28/10/2020.
PathaPadha Support
Quiz by PathaPadha Support, updated more than 1 year ago
PathaPadha Support
Created by PathaPadha Support about 5 years ago
23
0

Resource summary

Question 1

Question
Inline functions are useful when
Answer
  • Function is large with many nested loops
  • Function has many static variables
  • Function is small and we want to avoid function call overhead.
  • none of the above

Question 2

Question
#include<iostream> using namespace std; int x = 1; void fun() { int x = 2; { int x = 3; cout << ::x << endl; } } int main() { fun(); return 0; }
Answer
  • 1
  • 3
  • 2
  • 0

Question 3

Question
Predict the output of following C++ program #include<iostream> using namespace std; union A { int a; unsigned int b; A() { a = 10; } unsigned int getb() {return b;} }; int main() { A obj; cout << obj.getb(); return 0; }
Answer
  • Compiler Error: union can't have function
  • Compiler Error: can't access private members of A
  • 10
  • garbage value

Question 4

Question
Which of the following is true about inline functions and macros.
Answer
  • Inline functions do type checking for parameters, macros don't
  • Macros are processed by pre-processor and inline functions are processed in later stages of compilation.
  • Macros cannot have return statement, inline functions can.
  • Macros are prone to bugs and errors, inline functions are not
  • all of the above

Question 5

Question
How can we make a C++ class such that objects of it can only be created using new operator? If user tries to create an object directly, the program produces compiler error.
Answer
  • Not possible
  • By making destructor private
  • By making constructor private
  • By making both constructor and destructor private

Question 6

Question
Would destructor be called, if yes, then due to which vector? #include <iostream> #include <vector> using namespace std; class a { public : ~a() { cout << "destroy"; } }; int main() { vector <a*> *v1 = new vector<a*>; vector <a> *v2 = new vector<a>; return 0; }
Answer
  • v1
  • v2
  • v1&v2
  • no destructor call

Question 7

Question
#include<iostream> using namespace std; int x[100]; int main() { cout << x[99] << endl; }
Answer
  • 0
  • 99
  • run time error
  • unpredictable

Question 8

Question
#include<iostream> using namespace std; int main () { int cin; cin >> cin; cout << "cin" << cin; return 0; }
Answer
  • error in using cin keyword
  • cin+junk value
  • cin+input
  • run time error

Question 9

Question
A member function can always access the data in __________ , (in C++)
Answer
  • the class of which it is member
  • the object of which it is a member
  • the public part of its class
  • the private part of its class

Question 10

Question
Which of the following is not correct for virtual function in C++ ?
Answer
  • Virtual function can be static.
  • Must be declared in public section of class.
  • Virtual function should be accessed using pointers.
  • Virtual function is defined in base class.

Question 11

Question
Which of the following is not correct (in C++) ? 1.Class templates and function templates are instantiated in the same way 2.Class templates differ from function templates in the way they are initiated 3.Class template is initiated by defining an object using the template argument 4.Class templates are generally used for storage classes
Answer
  • 2,3,4
  • 2,3
  • 2
  • 4

Question 12

Question
In C++, polymorphism requires:
Answer
  • Inheritance, Virtual functions and references
  • References only
  • Virtual functions only
  • Inheritance only

Question 13

Question
Method over-riding can be prevented by using final as a modifier at ______
Answer
  • the start of the method declaration in the derived class.
  • the start of method declaration.
  • the start of derived class.
  • the start of the class.

Question 14

Question
In C, what is the effect of a negative number in a field width specifier?
Answer
  • the values are displayed right justified
  • the values are displayed centered
  • the values are displayed left justified
  • the values are displayed as negative numbers
Show full summary Hide full summary

Similar

Data Types
Jacob Sedore
Mapa Conceptual - Arreglos
ciroivan94
Examen POO C++ Final 1er Trimestre
kamyacademy
Vector
Ariel Sanchez
ITC Quiz 1
Ahmad Bilal0467
FEH C/C++ Quiz
Jared Sherrick
3. Сокеты Беркли. Мультиплексирование.
Sergei Fomin
OOP Phase Test (Summer)
b3014292
Mapa conceptual - Palabras reservadas
Giulio Gagliardi
COMP 206 Unit 3: The C in C++
Adriana Vincelli-Joma