C-Plus-Plus Questions March 21, 2023 | No Comments 0 votes, 0 avg 39 123456789101112131415 C-Plus-Plus Questions 1 / 15 1. What will be the output of the following C++ code? #include using namespace std; void square (int *x) { *x = (*x + 1) * (*x); } int main ( ) { int num = 10; square(&num); cout << num; return 0; } A. 100 B. compile time error C. 144 D. 110 2 / 15 2. What will be the output of the following C++ code? #include #include using namespace std; class Box { int capacity; public: Box(int cap){ capacity = cap; } friend void show(); }; void show() { Box b(10); cout<<"Value of capacity is: "< A. Value of capacity is: 10 B. Value of capacity is: 100 C. Error D. Segmentation fault 3 / 15 3. 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 4 / 15 4. Which of the following statement is correct about Virtual Inheritance? A. It is a technique to ensure that a private member of a base class can be accessed B. It is a technique to optimize the multiple inheritances C. It is a technique to avoid the multiple inheritances of the classes D. It is a C++ technique to avoid multiple copies of the base class into the derived or child classes 5 / 15 5. Which of the following is correct about this pointer in C++? A. this pointer is passed as a hidden argument in all static variables of a class B. this pointer is passed as a hidden argument in all the functions of a class C. this pointer is passed as a hidden argument in all non-static functions of a class D. this pointer is passed as a hidden argument in all static functions of a class 6 / 15 6. 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 7 / 15 7. 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 8 / 15 8. What is a binary operator? A. Operator that performs its action on a single operand B. Operator that performs its action on two operand C. Operator that performs its action on three operand D. Operator that performs its action on any number of operands 9 / 15 9. 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 10 / 15 10. What is abstract class in C++? A. Any Class in C++ is an abstract class B. Class from which any class is derived C. Class specifically used as a base class with atleast one virtual functions D. Class specifically used as a base class with atleast one pure virtual functions 11 / 15 11. Choose the type of loop which is guaranteed to execute at-least once? A. For-loop B. Do-while C. while D. None 12 / 15 12. Under which pillar of OOPS does base class and derived class relationship come? A. Polymorphism B. inheritance C. Encapsulation D. Abstraction 13 / 15 13. 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 14 / 15 14. 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 15 / 15 15. dentify the correct definition of ‘*’ operator in pointer. A. Address of operator B. value of address operator C. multiplication operator D. all of the above Your score is The average score is 22% LinkedIn Facebook Twitter VKontakte 0% Restart quiz Questions, Quiz