C-Plus-Plus Questions March 21, 2023 | No Comments 0 votes, 0 avg 221 123456789101112131415 C-Plus-Plus Questions 1 / 15 1. Find output of below program int main() { int c1,c2; int a = -8; int b = 3; c1 = --a + b; c2 = a-- + b; cout<<"c1="< A. c1=-7,c2=-4 B. c1=-7,c2=-3 C. c1=-4,c1=b-3 D. c1=-6,c2=-6 2 / 15 2. When will we use the function overloading? A. same function name but different number of arguments B. different function name but same number of arguments C. same function name but same number of arguments D. different function name but different number of arguments 3 / 15 3. Which option is false for the following code? class A { private : int sum(int x, int y) { return x+y; } public: A() { } A(int x, int y) { cout< A. Constructor will take 0 as default value of parameters if not passed B. Constructor can be created with zero argument C. Constructor prints sum, if two parameters are passed with object creation D. Constructor will give error if float values are passed 4 / 15 4. What will be the output of the following C++ code? #include using namespace std; int main () { int n; n = 43; cout << hex << n << endl; return 0; } A. 2c B. 2b C. 20 D. 50 5 / 15 5. How structures and classes in C++ differ? A. Structures by default hide every member whereas classes do not B. In Structures, members are public by default whereas, in Classes, they are private by default C. Structures cannot have private members whereas classes can have D. In Structures, members are private by default whereas, in Classes, they are public by default 6 / 15 6. What will be the output of the following C++ code? #include using namespace std; void swap(int &a, int &b); int main() { int a = 5, b = 10; swap(a, b); cout << "In main " << a << b; return 0; } void swap(int &a, int &b) { int temp; temp = a; a = b; b = temp; cout << "In swap " << a << b; } A. In swap 105 In main 105 B. In swap 105 In main 510 C. In swap 510 In main 105 D. In swap 510 In main 510 7 / 15 7. 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 8 / 15 8. What should be printed on screen? int main() { int x = 5; if(x++ == 5) cout<<"Five"< A. FiveSix B. Five C. Six D. None of these 9 / 15 9. Which of the following is the correct syntax of including a user defined header files in C++? A. #include [userdefined] B. #include “userdefined” C. #include <userdefined.h> D. #include <userdefined> 10 / 15 10. What is Pseudo-random number engines? A. Uses user input for random number generation B. Uses an algorithm that does not require any initial seed to generate random numbers C. Uses initial seed based algorithm to generate random numbers D. Random number generates depends on the program 11 / 15 11. 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 12 / 15 12. Where does the return statement returns the execution of the program? A. main function B. caller function C. same function D. block function 13 / 15 13. Choose the correct option which is mandatory in a function. A. return_type B. parameters C. function_name D. both a and c 14 / 15 14. What will be the output of the following C++ code? #include using namespace std; class Test { protected: int x; public: Test (int i):x(i) { } void fun() const { cout << "fun() const " << endl; } void fun() { cout << "fun() " << endl; } }; int main() { Test t1 (10); const Test t2 (20); t1.fun(); t2.fun(); return 0; } A. fun() fun() const B. fun() const fun() C. fun() fun() D. fun() const fun() const 15 / 15 15. 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 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