Skip to content
Related Articles

Related Articles

Improve Article

C++ | Templates | Question 8

  • Last Updated : 28 Jun, 2021
Geek Week


#include <iostream>
using namespace std;
template <int i>
void fun()
   i = 20;
   cout << i;
int main()
   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

Take a step-up from those “Hello World” programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.
My Personal Notes arrow_drop_up
Recommended Articles
Page :