A function template in C++ provides _____ level of generalization.

2016

A function template in C++ provides _____ level of generalization.

  1. A.

    4

  2. B.

    3

  3. C.

    2

  4. D.

    1

Attempted by 173 students.

Show answer & explanation

Correct answer: C

Answer: 2

Explanation:

  • Type parameters — placeholders for types, for example template<typename T> void func(T value). This lets the same function work with different types.

  • Non-type (value) parameters — compile-time constant values, for example template<int N> void func(int (&arr)[N]). This lets the template be specialized by values known at compile time.

Because function templates can be parameterized by both types and non-type values, they provide two levels of generalization.

Explore the full course: Mppsc Assistant Professor