C-Plus-Plus Questions March 21, 2023 | No Comments 0 votes, 0 avg 221 123456789101112131415 C-Plus-Plus Questions 1 / 15 1. Which of the following statements is correct about the formal parameters in C++? A. Parameters with which functions are called B. Parameters which are used in the definition of the function C. Variables other than passed parameters in a function D. Variables that are never used in the function 2 / 15 2. What will be the output of the following C++ code? #include #include using namespace std; int main() { cout<::type>::value; cout<::type>::value; return 0; } A. 11 B. 12 C. 21 D. 22 3 / 15 3. How many times ‘its a while loop’ should be printed? int main() { int i = 1 ; i = i - 1 ; while(i) { cout<<"its a while loop"; i++ ; } return 0; } A. 1 B. 2 C. O D. infinite times 4 / 15 4. What will be the output of the following C++ code? #include 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 < A. <pre><code> Volume of Box1 : 210 Volume of Box2 : 1560 Volume of Box3 : 5400</code></pre> B. <pre><code>Volume of Box1 : 200 Volume of Box2 : 1560 Volume of Box3 : 5400</code></pre> C. <pre><code> Volume of Box1 : 210 Volume of Box2 : 1550 Volume of Box3 : 5400</code></pre> D. <pre><code> Volume of Box1 : 200 Volume of Box2 : 1000 Volume of Box3 : 5260</code></pre> 5 / 15 5. What will be the output of the following C++ code snippet? #include #include using namespace std; int main () { int array[] = {0, 2, 4, 6, 7, 5, 3}; int n, result = 0; for (n = 0; n < 8; n++) { result += array[n]; } cout << result; return 0; } A. 21 B. 27 C. 26 D. 25 6 / 15 6. What is virtual inheritance in C++? A. C++ technique to enhance multiple inheritance B. C++ technique to ensure that a private member of the base class can be accessed somehow C. C++ technique to avoid multiple inheritances of classes D. C++ technique to avoid multiple copies of the base class into children/derived class 7 / 15 7. Among the following, which statement is correct about the Modularity? A. Modularity means hiding the parts of the program B. Modularity refers to dividing a program into subsequent small modules or independent parts C. It refers to overloading the program's part D. Modularity refers to wrapping the data and its functionality into a single entity 8 / 15 8. What will be the output of the following C++ code? #include #include #include using namespace std; int main () { string mystr; float price = 0; int quantity = 0; cout << "Enter price: "; getline (cin, mystr); stringstream(mystr) >> price; cout << "Enter quantity: "; getline (cin, mystr); stringstream(mystr) >> quantity; cout << "Total price: " << price * quantity << endl; return 0; } A. 50 B. Depends on value you enter C. Error D. 100 9 / 15 9. What will be the output of the following C++ code? #include using namespace std; void copy (int& a, int& b, int& c) { a *= 2; b *= 2; c *= 2; } int main () { int x = 1, y = 3, z = 7; copy (x, y, z); cout << "x =" << x << ", y =" << y << ", z =" << z; return 0; } A. 2 5 10 B. 2 4 5 C. 2 6 14 D. 2 4 9 10 / 15 10. Which of the following loops is best when we know the number of iterations? A. while loop B. for loop C. do-while loop D. all of the above 11 / 15 11. Which of the following is not a type of inheritance? A. Multiple B. Multilevel C. Distributed D. Heirarchical 12 / 15 12. What will be the output of the following C++ code? #include using namespace std; template T max (T &a, T &b) { cout << "Template Called "; return (a > b)? a : b; } template <> int max (int &a, int &b) { cout << "Called "; return (a > b)? a : b; } int main () { int a = 10, b = 20; cout << max (a, b); } A. Template Called 20 B. Called 20 C. Error D. Segmentation fault 13 / 15 13. Which of the following options correctly explains the concept of Polymorphism? A. int func(float); float func(int, int, char); B. int func(int); int func(int); C. int func(int, int); float func1(float, float); D. None of the above 14 / 15 14. What will be the output of the following C++ code? #include using namespace std; int gcd (int a, int b) { int temp; while (b != 0) { temp = a % b; a = b; b = temp; } return(a); } int main () { int x = 15, y = 25; cout << gcd(x, y); return(0); } A. 15 B. 25 C. 375 D. 5 15 / 15 15. Observer the given C++ program carefully and choose the correct output from the given options: #include #include using namespace std; int main() { cout<::value; // case A cout<::value; // case B cout<::value; // case c return 0; } A. 11O B. OO1 C. O1O D. none of the above Your score isThe average score is 33% LinkedIn Facebook VKontakte 0% Restart quiz By WordPress Quiz plugin Written by Shubhranshu Shekhar, who has trained 20000+ students in coding. Kritika Papne Questions, Quiz