C++ | Templates | Question 8

Output?

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(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 DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.