C-Plus-Plus QuestionsBy Kritika Papne / March 21, 2023 0 votes, 0 avg 231 123456789101112131415 C-Plus-Plus Questions 1 / 15 1. 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 2 / 15 2. Consider the following given program and choose the most appropriate output from the given options: #include using namespace std; class Base { public: Base() { cout<<"Constructing Base n"; } ~Base() { cout<<"Destructing Base n"; } }; class Derived: public Base { public: Derived() { cout<<"Constructing Derived n"; } ~Derived() { cout<<"Destructing Derived n"; } }; int main(void) { Derived *d = new Derived(); Base *b = d; delete b; return 0; } A. Constructing Base, Constructing Derived, Destructing Base, Destructing Derived B. Constructing Base, Constructing Derived, Destructing Base C. Constructing Base, Constructing Derived, Destructing Derived, Destructing Base D. none of the above 3 / 15 3. What will be the output of the following C++ code? #include using namespace std; int main() { int a = 5; float b; cout << sizeof(++a + b); cout << a; return 0; } A. 2 5 B. 4 5 C. 4 6 D. 2 6 4 / 15 4. What did we call an array of the one-dimensional array? A. Single Dimensional array B. Multi-Dimensional array C. 2D Array (or 2-Dimensional array) D. Both A and B 5 / 15 5. What is the output of the given program? #include < stdio.h > using namespace std; int main() { int array[] = {10, 20, 30}; cout << -2[array]; return 0; } A. -30 B. -15 C. garbage value D. compiler error 6 / 15 6. What will be the output of the following C++ code? #include using namespace std; int main() { int a, b; int* c; c = &a; a = 200; b = 200; *c = 100; b = *c; cout << *c << " " << b; return 0; } A. 100 200 B. 100 0 C. 200 200 D. 100 100 7 / 15 7. What is dangling pointer? A. A pointer pointing to NULL B. Pointer pointing to memory location which has been freed C. Pointer which is pointing to new location D. None of these 8 / 15 8. What is the output of this C++ program in the “test.txt” file? #include using namespace std; int main () { long pos; ofstream outfile; outfile.open ("test.txt"); outfile.write ("This is an apple",16); pos = outfile.tellp(); outfile.seekp (pos - 7); outfile.write (" sam", 4); outfile.close(); return 0; } A. This is an apple B. apple C. sample D. This is a sample 9 / 15 9. 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 10 / 15 10. 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 11 / 15 11. What is the difference between delete and delete[] in C++? A. delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case B. delete is used to delete normal objects whereas delete[] is used to pointer objects C. delete is a keyword whereas delete[] is an identifier D. delete is used to delete single object whereas delete[] is used to multiple(array/pointer of) objects 12 / 15 12. 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 13 / 15 13. 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 14 / 15 14. What is do-while loop also known as? A. Exit Control B. Entry Control C. Per Tested D. all of the above 15 / 15 15. 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 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