C++ Basics Assessment Test

C++ Basics

 44 Minutes
 22 Questions


This test covers a wide range of topics related to the C++ programming language. It includes questions on the Standard Template Library (STL), the Standard Library, Object Oriented Programming, Compound Data Types, Basics, Algorithms and Advanced Concepts. The test is designed to assess a candidate's knowledge and understanding of the C++ language and its various components.


Example Question:

Multiple-Choice

In the following code we call the function template twice. In the second call we don't specify the type (long) when calling the function template. Will it work?


#include <iostream>
using namespace std;

template <class T>
T FetchMax (T a, T b) {
  T result;
  result = (a>b)? a : b;
  return (result);
}

int main () {
  int i=5, j=6, k;
  long l=10, m=5, n;
  k=FetchMax<int>(i,j);
  n=FetchMax(l,m);
  cout << k << endl;
  cout << n << endl;
  return 0;
}
Answers
1. No, you have to specify the function template type
2. Yes, the compiler can find out automatically which data type has to instantiate from the return type of the function template
3. Yes, in this case the compiler can find out automatically which data type it has to instantiate from the generic type T that is used as a parameter for FetchMax