1
Loading subject content…
Loading subject content…
Loading practice questions…
What will be the output of the program?
#include <iostream>
using namespace std;
template <typename T>
struct Box { T v; T get() { return v; } };
int main() {
Box<int> b{5};
Box<char> c{'z'};
cout << b.get() << c.get() << endl;
return 0;
}What will be the output of the program?
#include <iostream>
using namespace std;
template <typename T>
struct Stack {
T d[10]; int top = 0;
void push(T v) { d[top++] = v; }
T pop() { return d[--top]; }
};
int main() {
Stack<int> s;
s.push(4); s.push(9);
cout << s.pop() << s.pop() << endl;
return 0;
}What will be the output of the program?
#include <iostream>
using namespace std;
template <typename T>
void show(T v) { cout << "T"; }
template <>
void show<int>(int v) { cout << "int"; }
int main() {
show(1.0);
show(1);
cout << endl;
return 0;
}