Skip to content
Related Articles

Related Articles

C++ | Templates | Question 8
  • Last Updated : 16 Oct, 2013

Output?




#include <iostream>
using namespace std;
  
template <int i>
void fun()
{
   i = 20;
   cout << i;
}
  
int main()
{
   fun<10>();
   return 0;
}


(A) 10
(B) 20
(C) Compiler Error


Answer: (C)

Explanation: Compiler error in line “i = 20;”

Non-type parameters must be const, so they cannot be modified.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :