⟩ Explain static type checking?
Static type checking performs the type checking operation before the execution of the program. To perform this operation, the arguments, expressions, variables must be given a data type.
Static type checking performs the type checking operation before the execution of the program. To perform this operation, the arguments, expressions, variables must be given a data type.
Which keyword can be used in template? a) class b) typename c) both a & b d) function
What is the output of this program?
#include <iostream>
using namespace std;
template <class T, int N>
class mysequence
{
T memblock [N];
public
void setmember (int x, T value);
T getmember (int x);
};
template <class T, int N>
void mysequence<T,N> setmember (int x, T value)
{
memblock[x] = value;
}
template <class T, int N>
T mysequence<T,N> getmember (int x)
{
return memblock[x];
}
int main ()
{
mysequence <int, 5> myints;
mysequence <double, 5> myfloats;
myints.setmember (0, 100);
myfloats.setmember (3, 3.1416);
cout << myints.getmember(0) << 'n';
cout << myfloats.getmember(3) << 'n';
return 0;
}
a) 100
b) 3.1416
c) 100
3.1416
d) none of the mentionedWhat is the output of this program?
#include <iostream>
using namespace std;
template <class T>
T max (T a, T b)
{
return (a>b?ab);
}
int main ()
{
int i = 5, j = 6, k;
long l = 10, m = 5, n;
k = max(i, j);
n = max(l, m);
cout << k << endl;
cout << n << endl;
return 0;
}
a) 6
b) 6
10
c) 5
10
d) 6
5What is the output of this program?
#include <iostream>
using namespace std;
template <class type>
class Test
{
public
Test()
{
};
~Test()
{
};
type Funct1(type Var1)
{
return Var1;
}
type Funct2(type Var2)
{
return Var2;
}
};
int main()
{
Test<int> Var1;
Test<double> Var2;
cout << Var1.Funct1(200);
cout << Var2.Funct2(3.123);
return 0;
}
a) 100
b) 200
c) 3.123
d) 200 3.123Can you please explain the difference between a template class and class template?
What is meant by template parameter? a) It can be used to pass a type as argument b) It can be used to evaluate a type. c) It can of no return type d) None of the mentioned
Which parameter is legal for non-type template? a) pointer to member b) object c) class d) none of the mentioned
Why we use template-template parameter? a) binding b) rebinding c) both a & b d) none of these
What is the output of this program?
#include <iostream>
using namespace std;
template <typename T, int count>
void loopIt(T x)
{
T val[count];
for(int ii = 0; ii < count; ii++)
{
val[ii] = x++;
cout << val[ii] << endl;
}
};
int main()
{
float xx = 2.1;
loopIt<float, 3>(xx);
}
a) 2.1
b) 3.1
c) 4.1
d) 2.1
3.1
4.1Is the size of character literals different in C and C++? a) Implementation defined b) Can't say c) Yes, they are different d) No, they are not different