PLAY READ BLOG

Assess your experience with C++

I estimate it would take you 39 steps in 13 minutes to Assess your experience with C++.
Variadic templates in C++11 allow the programmer to write functions that:
1. Take an arbitrary number of arguments in a type-safe way.

2. Have all the argument handling logic resolved at run-time

3. Allow a variety of return types.

4. Allow custom data structures other than tuples.
  • 1.
  • 2.
  • 3.
  • 4.
What is the value of z after executing the following code snippet?

unsigned int x = 3;
unsigned int y = 5;
unsigned int z = x | y;
  • This code will not compile
  • 7
  • 8
  • 6
Given the following code:

const int* ptr;

Which of the following can be changed?
  • ptr only
  • Neither ptr nor *ptr
  • Both ptr and *ptr
  • *ptronly
If you wanted to go through all elements of a vector v in reverse order, what for loop would you write?
1. for (auto it = rbegin(v); it != rend(v); it++)

2. for (auto it = rbegin(v); it != rend(v); it--)

3. for (auto it = end(v); it != begin(v); it--)

4. Reverse the vector then go through as usual
  • 1.
  • 2.
  • 3.
  • 4.
In a container such as an std::vector, the iterator returned by a call to end() points to:
1. The last element in the container.

2. The end() function cannot be applied to a std::vector.

3. The element after the last element in the container.

4. The element before the last element in the container.
  • 1.
  • 2.
  • 3.
  • 4.
If you write past the end of a locally-allocated C style array, what happens?
1. Nothing when you do it; possible strange errors later

2. An exception is thrown

3. The array is invalidated

4. The information is lost but nothing else is affected
  • 1.
  • 2.
  • 3.
  • 4.
What is the output of the following code snippet?

int a = 1;
unsigned b = -1;
if(a > b)
cout << "a is greater than b";
else
cout << "a is not greater than b";
  • Code will not compile
  • a is not greater than b
  • a is greater than b
  • Runtime error
What is the output of the following C++ program ?

#include <iostream>
using namespace std;
class SomeClass
{
public:
static int id;
SomeClass() { id ++; }
static int getID() { return id; }
};
int SomeClass::id = 0;
void main()
{
cout << SomeClass::getID() << ",";
SomeClass id1, id2, ids[2];
cout << SomeClass::getID();
}
  • 0,4
  • 0,0
  • 0,2
  • No output due to compiler error
When you use the new operator to create an object on the free store, it returns:
1. a pointer to the object that was created.

2. true or false according to whether creation succeeded or failed.

3. the actual object that was created.

4. a smart pointer to the object that was created.

5. a reference to the object that was created.
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
💡FUN FACT 💡As of 2019, C++ remains the third most popular programming language, behind Java and C.
C++ keywords, punctuation, and other language rules can be changed by:
1. Nobody, C++ keywords and rules cannot change

2. Any C++ compiler vendor

3. The ISO C++ committee

4. Bjarne Stroustrup, who invented C++
  • 1.
  • 2.
  • 3.
  • 4.
What is the output of the following code involving enums?

enum words { four, score, and, seven, years, ago };
cout << seven << endl;
  • seven
  • 3
  • 4
  • 87
Which exception and type is caught in the following try/catch block?

try
{
string s1("abc");
string s2("def");
s1.append(s2, 4, 3);
cout << s1 << endl;
}
catch (exception &e)
{
cerr << "Exception: " << e.what() << endl;
cerr << "Type: " << typeid(e).name() << endl;
};
1. runtime exception, class std::runtime_error

2. vector<T> too long, class std::length_error

3. invalid string position, class std::out_of_range

4. No exception occurs
  • 1.
  • 2.
  • 3.
  • 4.
Some developers prefer to use '\n' rather than std::endl for performance reasons. Which of these statements is true when sending output to a file?
1. Both approaches flush the output and there is no performance difference

2. You cannot use std::endl when writing to a file

3. '\n' is slower, because there is no flush

4. - std::endl is slower, because of the flush
  • 1.
  • 2.
  • 3.
  • 4.
Given this code: int* const ptr; Which of the following can be changed?
  • Both *ptrand ptr
  • Neither *ptr or ptr
  • ptr only
  • *ptr only
Which of these is a difference between a struct and class?
1. A class implements validation and business logic; a struct cannot

2. The default access is public in a struct; private in a class

3. A class can have a constructor; a struct cannot

4. A class can have functions; a struct cannot
  • 1.
  • 2.
  • 3.
  • 4.
Which is true of specifying private, protected, and public in a class declaration?
1. The order is irrelevant, but each term can only be used once

2. They can be used anywhere, as many times as desired, and in any order

3. The order must be: private, protected, then public

4. The order must be: public, protected, then private
  • 1.
  • 2.
  • 3.
  • 4.
To find a character in a std::string, what do you use ?
  • The member function substr()
  • The member function find()
  • Write a loop that checks each character
  • A free function called find()
If you use multiple overloads of a function instead of default parameters, what bad thing might happen?
1. Exceptions will not work properly

2. Code that calls the function is more likely to have a compiler error

3. Your code will run more slowly

4. A developer has to read the .cpp file to understand the differences among the overloads
  • 1.
  • 2.
  • 3.
  • 4.
Get Started   

Or consider 74 other intentions.