1. Which is a function that returns a non zero value to indicate an I/O stream error?
2. Consider the following code: class A { typedef int I; // private member I f(); friend I g(I); static I x; }; Which of the following are valid:
3. Answer the question that follows. 1 class Car 2 { 3 private: 4 int Wheels; 5 6 public: 7 Car(int wheels = 0) 8 : Wheels(wheels) 9 { 10 } 11 12 int GetWheels() 13 { 14 return Wheels; 15 } 16 }; 17 main() 18 { 19 Car c(4); 20 cout << 'No of wheels:' << c.GetWheels(); 21 } Which of the following lines from the sample code above are examples of data member definition?
4. Consider the following code: #include int main(int argc, char* argv[]) { enum Colors { red, blue, white = 5, yellow, green, pink }; Colors color = green; printf('%d', color); return 0; } What will be the output when the above code is compiled and executed?
5. Consider the following code: #define SQ(a) (a*a) int answer = SQ(2 + 3); What will be the value of answer after the above code executes?
6. Consider two classes A and B: class A { private: int x; float y; public: friend class B; }; class B { }; Which of the following is true?
7. Which is NOT valid C++ casts
8. Answer the question that follows. class Grandpa { } ; class Ma : virtual public Grandpa { } ; class Pa : virtual public Grandpa { } ; class Me : public Ma, public Pa, virtual public Grandpa { } ; How many instances of Grandpa will each instance of Me contain?
9. Which techniques should you use to handle a destructor that fails?
10. Sample Code typedef char *monthTable[3]; Referring to the code above, which of the following choices creates two monthTable arrays and initializes one of the two?
11. Which statement is FALSE with regard to destructors
12. Answer the question that follows. class X { int i; protected: float f; public: char c; }; class Y : private X { }; Referring to the sample code above, which of the following data members of X are accessible from class Y
13. Answer the question that follows: char **foo; /* Missing code goes here */ for(int i = 0; i < 200; i++) { foo[i] = new char[100]; } Referring to the sample code above, what is the missing line of code?
14. Output of the code? class Shape { public: virtual void draw() = 0; }; class Rectangle: public Shape { public: void draw() { // Code to draw rectangle } //Some more member functions..... }; class Circle : public Shape { public: void draw() { // Code to draw circle } //Some more member functions..... }; int main() { Shape objShape; objShape.draw(); } What happens if the above program is compiled and executed?
15. The c++ operator ____ is used to create dynamic variables.
16. Which STL class is the best fit for implementing a collection of data that is always ordered so that the pop operation always gets the greatest of the elements? Suppose you are interested only in push and pop operations.
17. What is the value of x after running this code? int x=10, a=-3; x=+a;
18. Consider a pointer to void, named ptr, which has been set to point to a floating point variable g. Which choice is a valid way to dereference ptr to assign its pointed value to a float variable f later in the program? float g; void *ptr=&g;
19. What is the statement below equivalent to? sprite->x
20. Which of the following STL classes is the best fit for implementing a phonebook? Suppose each entry contains a name and a phone number, with no duplicates, and you want to have lookup by name.
21. Which STL class is the best fit for implementing a phonebook? Suppose each entry contains a name and a phone number, with no duplicates, and you want to have lookup by name.
22. What is an include guard?
23. When placed in a valid execution context, which statement will dynamically allocate memory from the heap for an integer of value 11?
24. Which choice best describes the type long?
25. Which of the following types has the closest functionality to a class?
C++ MCQs | Topic-wise