Skip to content

Tag Archives: Templates

The task is to implement some important functions of stack like pop(), push(), display(), topElement(), isEmpty(), isFull() using class template in C++. Stack is a… Read More
Preprocessor Directives are programs that process our source code before compilation. There are a number of steps involved between writing a program and executing a… Read More
Prerequisite: Templates in C++ Generally, a C++ template, with a single argument looks like this: template<typename template_name> But it has been seen that a template… Read More
A C++ tuple is a container that can store multiple values of multiple types in it. We can access the elements of the tuple using… Read More
Output? #include <iostream> using namespace std;     template<int n> struct funStruct {     static const int val = 2*funStruct<n-1>::val; };     template<> struct funStruct<0> {     static… Read More
Output? #include <iostream> using namespace std;    template <class T> T max (T &a, T &b) {     return (a > b)? a : b; }… Read More
Output? #include <iostream> using namespace std;    template <int i> void fun() {    i = 20;    cout << i; }    int main() {    fun<10>();… Read More
Output of following program. #include <iostream> using namespace std;    template <class T, int max> int arrMin(T arr[], int n) {    int m = max;… Read More
Output of following program? Assume that the size of int is 4 bytes and size of double is 8 bytes, and there is no alignment… Read More
Output of following program? Assume that the size of char is 1 byte and size of int is 4 bytes, and there is no alignment… Read More
Output of following program? #include <iostream> using namespace std;    template <class T> class Test { private:     T val; public:     static int count;     Test()  {  … Read More
#include <iostream> using namespace std;    template <typename T> T max(T x, T y) {     return (x > y)? x : y; } int main()… Read More
Predict the output? #include <iostream> using namespace std;    template <typename T> void fun(const T&x) {     static int count = 0;     cout << "x =… Read More
Which of the following is true about templates. 1) Template is a feature of C++ that allows us to write one code for different data… Read More