C-Plus-Plus Questions March 21, 2023 | No Comments 0 votes, 0 avg 223 123456789101112131415 C-Plus-Plus Questions 1 / 15 1. Which part of memory is used for the allocation of local variables declared inside any function. A. Heap B. Address Space C. Stack D. Depends on Compiler 2 / 15 2. What will be the output of the following C++ code? #include 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 3 / 15 3. 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 4 / 15 4. Which one of the following is the correct definition of the "is_array();" function in C++? A. It checks that the specified array of single dimension or not B. It checks that the specified variable is of the array or not C. It checks that the array specified of multi-dimension or not D. both a and c 5 / 15 5. what will be the output of the following C++ code snippet? int main() { int i=0,x=0; for(i=1;i<10;i*=2) { x++; cout< A. 1234567899 B. 12345678910 C. 123455 D. 12344 6 / 15 6. Would destructor be called, if yes, then due to which vector? #include #include using namespace std; class a { public : ~a() { cout << "destroy"; } }; int main() { vector *v1 = new vector; vector *v2 = new vector; return 0; } A. v1 B. v2 C. v1 and v2 D. no destructor call 7 / 15 7. What is the use of is_same() function in C++? A. To check if a variable is array type or not B. To check whether two variables have the same characteristics C. To check if two variable is of array type or not D. To check whether two variables are different or not 8 / 15 8. What will be the output of the following C++ code? #include using namespace std; void Sum(int a, int b, int & c) { a = b + c; b = a + c; c = a + b; } int main() { int x = 2, y =3; Sum(x, y, y); cout << x << " " << y; return 0; } A. 2 3 B. 6 9 C. 2 15 D. compile time error 9 / 15 9. Read 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. 121 B. 321 C. 123 D. O1O 10 / 15 10. What is the use of the indentation in c++? A. distinguishes between comments and inner data B. distinguishes between comments and outer data C. distinguishes between comments and code D. distinguishes between comments and outer data 11 / 15 11. Where does the return statement returns the execution of the program? A. main function B. caller function C. same function D. block function 12 / 15 12. What will be the output of the following C++ code? #include 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 < A. 213 B. 210 C. 215 D. 217 13 / 15 13. Pick the incorrect statement about inline functions in C++? A. Saves overhead of a return call from a function B. They are generally very large and complicated function C. These functions are inserted/substituted at the point of call D. They reduce function call overheads 14 / 15 14. 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 15 / 15 15. What will be the output of the following C++ code? #include #include using namespace std; int main() { cout<::value; cout<::value; cout<::value; return 0; } A. O11 B. 1O1 C. O1O D. 11O Your score isThe average score is 32% 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