Which of the following is true regarding templates in C++?

17 views
  • Templates cannot be used for function overloading.
  • Templates can only be used for classes.
  • Templates can be used for both functions and classes. (Correct Answer)
  • Templates cannot be used for type-dependent operations.

Explanation

Correct answer: c) Templates can be used for both functions and classes.

Explanation: Templates are a powerful feature in C++ that allows for generic programming. Templates can be used for both functions and classes, allowing for a wide range of reusable code. Option a) is false, as templates are commonly used for function overloading. Option b) is false, as templates can be used for both classes and functions. Option d) is false, as templates are specifically designed for type-dependent operations.

Comments (0)

No comments yet. Be the first to comment!

Want to practice more?

Explore thousands of MCQs across every exam category on Exams Nepal.

Find More MCQs