1. If you make a function call TestFunction('a') and all of the following options are available, which version of the function will be called?
void TestFunction();
void TestFunction(int param1, int param2=0);
void TestFunction(std::string param);
void TestFunction(char param);
2. What is the correct syntax for declaring a template function in C++?
template <typename T> void foo(T);
<template> void foo(T);
void foo<template T>(T);
<template typename T> void foo(T);
3. How can the logical AND operator (&&) be used in C++?
&&
4. If the following code compiles successfully, which is NOT a possible type for "out_stream"? out_stream << "Hello test taker!";
out_stream
out_stream << "Hello test taker!";
std::ofstream
std::ostream &
std::stringstream
std::string
5. When compiling a large C++ project with many files, which of the following is NOT always good advice?
6. What is a difference between pointers and references in C++? +
7. If you have an int variable called "id_num" and you want to convert it to a std::string called "id_name", which of these lines will work?
int
id_num
id_name
std::string id_name(id_num);
std::string id_name = std::stol(id_num);
std::string id_name = static_cast<std::string>(id_num);
std::string id_name = std::to_string(id_num);
8. What will the following code output? std::vector<int> v{1,2,3,4}; std::cout << std::accumulate(v.begin()+1, v.end()-1, 0) << std::endl;
std::vector<int> v{1,2,3,4};
std::cout << std::accumulate(v.begin()+1, v.end()-1, 0) << std::endl;
0
10
5
9
4
9. What does the following line of code do? assert(x == 10);
assert(x == 10);
x
10. Which of the following is an illegal use of the keyword "auto"?
auto & my_stream = std::cout;
auto i;
auto my_var = std::string("abcd");
auto my_str = std::string("Test.");
Click Check Answers to identify any errors and try again. Click Show Answers if you also want to know which answer is the correct one.