5.5 - Transition from C to C++.


Back Button Home

5.5.1 - Introduction to Transition from C to C++.


1. Which of the following is a key feature added in C++ but not available in C?
  • (A) Pointers
  • (B) Classes
  • (C) Functions
  • (D) Arrays
Correct Answer: (B) Classes
2. How is a function parameter passed by reference in C++?
  • (A) By using & after the type
  • (B) By using & before the type
  • (C) By using *
  • (D) By using &&
Correct Answer: (A) By using & after the type
3. What is the default value in C++ used for?
  • (A) To store garbage values
  • (B) To assign a constant value to the arguments
  • (C) To assign a default value to function parameters
  • (D) To return a value from a function
Correct Answer: (C) To assign a default value to function parameters
4. What is the syntax for calling a function by reference in C++?
  • (A) type* identifier
  • (B) type& identifier
  • (C) type identifier&
  • (D) type&* identifier
Correct Answer: (B) type& identifier
5. Which of the following is a new type introduced in C++ that extends the C struct?
  • (A) Object
  • (B) Class
  • (C) Pointer
  • (D) Variable
Correct Answer: (B) Class
6. Which keyword is used in C++ to define public members of a class?
  • (A) private
  • (B) protected
  • (C) public
  • (D) default
Correct Answer: (C) public
7. Which function is called automatically when an object of a class is created in C++?
  • (A) Destructor
  • (B) Operator
  • (C) Constructor
  • (D) Function pointer
Correct Answer: (C) Constructor
8. What is the purpose of a destructor in C++?
  • (A) It allocates memory
  • (B) It deallocates memory
  • (C) It inherits the base class
  • (D) It initializes variables
Correct Answer: (B) It deallocates memory
9. In C++, what is the symbol for the destructor function?
  • (A) ::
  • (B) ~
  • (C) ->
  • (D) &
Correct Answer: (B) ~
10. Which of the following features distinguishes C++ from C?
  • (A) File handling
  • (B) Classes and Objects
  • (C) Functions
  • (D) Arrays
Correct Answer: (B) Classes and Objects
11. What is the scope resolution operator in C++ used for?
  • (A) To define global variables
  • (B) To access class member functions outside the class
  • (C) To create a destructor
  • (D) To overload operators
Correct Answer: (B) To access class member functions outside the class
12. Which of the following is true about function overloading in C++?
  • (A) Functions with different names can have the same arguments
  • (B) Functions with the same name must have different parameters
  • (C) Functions with the same name can have the same parameters
  • (D) Functions cannot be overloaded in C++
Correct Answer: (B) Functions with the same name must have different parameters
13. What is the main advantage of using a constructor in C++?
  • (A) It initializes class objects automatically
  • (B) It allocates memory dynamically
  • (C) It deallocates memory
  • (D) It hides data from other functions
Correct Answer: (A) It initializes class objects automatically
14. What is the default access specifier for class members in C++?
  • (A) public
  • (B) private
  • (C) protected
  • (D) global
Correct Answer: (B) private
15. Which feature of C++ allows a function to behave differently based on the arguments passed?
  • (A) Overloading
  • (B) Constructors
  • (C) Destructors
  • (D) Pointers
Correct Answer: (A) Overloading
16. Which C++ feature enables hiding the implementation details from the user?
  • (A) Data abstraction
  • (B) Function pointers
  • (C) Virtual functions
  • (D) Polymorphism
Correct Answer: (A) Data abstraction
17. Which of the following is an example of polymorphism in C++?
  • (A) Function overloading
  • (B) Pointers
  • (C) Inline functions
  • (D) Constructors
Correct Answer: (A) Function overloading
18. What is the purpose of the inline keyword in C++?
  • (A) To reduce the execution time of the program
  • (B) To define large functions
  • (C) To improve memory management
  • (D) To implement file handling
Correct Answer: (A) To reduce the execution time of the program
19. Which of the following represents a correct constructor declaration for a class named "Test"?
  • (A) void Test();
  • (B) Test();
  • (C) int Test();
  • (D) ~Test();
Correct Answer: (B) Test();
20. Which of the following is true for destructors in C++?
  • (A) They can take parameters
  • (B) They are called manually
  • (C) They are called automatically when an object is destroyed
  • (D) They can be overloaded
Correct Answer: (C) They are called automatically when an object is destroyed
21. Which of the following is a feature of Object-oriented Programming (OOP)?
  • (A) Encapsulation
  • (B) Inheritance
  • (C) Polymorphism
  • (D) All of the above
Correct Answer: (D) All of the above
22. What is the term for combining data and functions that operate on the data in a single unit?
  • (A) Inheritance
  • (B) Encapsulation
  • (C) Polymorphism
  • (D) Overloading
Correct Answer: (B) Encapsulation
23. Which of the following is NOT a type of inheritance in C++?
  • (A) Single inheritance
  • (B) Multiple inheritance
  • (C) Hybrid inheritance
  • (D) Pointer inheritance
Correct Answer: (D) Pointer inheritance
24. In OOP, which of the following supports dynamic method resolution?
  • (A) Polymorphism
  • (B) Encapsulation
  • (C) Inheritance
  • (D) Abstraction
Correct Answer: (A) Polymorphism
25. Which keyword is used to define an abstract class in C++?
  • (A) abstract
  • (B) virtual
  • (C) private
  • (D) protected
Correct Answer: (B) virtual
26. What is the relationship between base class and derived class in inheritance?
  • (A) IS-A relationship
  • (B) HAS-A relationship
  • (C) PART-OF relationship
  • (D) USES-A relationship
Correct Answer: (A) IS-A relationship
27. Which of the following is used to prevent a class from being inherited?
  • (A) Final keyword
  • (B) Constant keyword
  • (C) Static keyword
  • (D) Virtual keyword
Correct Answer: (A) Final keyword
28. Which operator is used to access the members of a class in C++?
  • (A) ->
  • (B) . (dot operator)
  • (C) *
  • (D) &
Correct Answer: (B) . (dot operator)
29. Which type of function can have different implementations depending on the object that calls it?
  • (A) Inline function
  • (B) Virtual function
  • (C) Friend function
  • (D) Constructor
Correct Answer: (B) Virtual function
30. A constructor is called when:
  • (A) An object is created
  • (B) An object is destroyed
  • (C) A function is called
  • (D) None of the above
Correct Answer: (A) An object is created
31. Which of the following statements about destructors is true?
  • (A) Destructors can be overloaded
  • (B) Destructors cannot take arguments
  • (C) Destructors are called manually
  • (D) Destructors are inherited
Correct Answer: (B) Destructors cannot take arguments
32. In C++, what happens when a class inherits from another class with public access?
  • (A) Only private members of the base class become private in the derived class
  • (B) Public members of the base class remain public in the derived class
  • (C) Protected members of the base class become private in the derived class
  • (D) All members of the base class become private in the derived class
Correct Answer: (B) Public members of the base class remain public in the derived class
33. In multiple inheritance, if two base classes have a function with the same name, how can you resolve the ambiguity in the derived class?
  • (A) Use scope resolution operator
  • (B) Overload the function
  • (C) Use polymorphism
  • (D) Declare the function as final
Correct Answer: (A) Use scope resolution operator
34. Which concept allows functions to be defined with the same name but with different signatures in C++?
  • (A) Encapsulation
  • (B) Overloading
  • (C) Abstraction
  • (D) Inheritance
Correct Answer: (B) Overloading
35. What is the purpose of a copy constructor?
  • (A) To initialize an object using another object of the same class
  • (B) To allocate dynamic memory to objects
  • (C) To free the memory of an object
  • (D) To create a new class from a base class
Correct Answer: (A) To initialize an object using another object of the same class
36. Which of the following is a valid declaration of a pure virtual function in C++?
  • (A) virtual void show() {}
  • (B) virtual void show() = 0;
  • (C) void show() {}
  • (D) void show() = 0;
Correct Answer: (B) virtual void show() = 0;
37. Which of the following C++ concepts provides the ability to define the same function in multiple derived classes and invoke the correct one based on the object type?
  • (A) Encapsulation
  • (B) Inheritance
  • (C) Polymorphism
  • (D) Abstraction
Correct Answer: (C) Polymorphism
38. Which of the following is NOT an access specifier in C++?
  • (A) Private
  • (B) Protected
  • (C) Public
  • (D) Friend
Correct Answer: (D) Friend
39. In C++, the keyword this refers to:
  • (A) The current object
  • (B) The parent class
  • (C) A static member function
  • (D) A global object
Correct Answer: (A) The current object
40. Which of the following is used to release memory allocated to an object in C++?
  • (A) Constructor
  • (B) Destructor
  • (C) Copy constructor
  • (D) Inline function
Correct Answer: (B) Destructor