C++17 in Detail: A Deep Dive Educative Quiz Answers

Get C++17 in Detail: A Deep Dive Educative Quiz Answers

C++ started in 1979 as an experiment, before being officially launched in 1983. In 1998, its first ISO standard was released. What started as an experimental language has quickly turned into a platform for solving complex problems that drive many industries: gaming, finance, data centres, vehicles, and even software for space missions, among many others. The latest release, C++17, builds upon the functionality of previous versions by further diversifying the power of C++ and increasing the language’s readability.

This course describes all the significant changes in C++17 and will give you the essential knowledge to stay at the edge of the latest features. What’s more, each section contains lots of practical examples and uses a bottom-up approach to give you a more comfortable start. If you have a moderate understanding of C++, this course is highly recommended as the next step in mastering the modern form of this language.

Enroll on Educative

Quiz 1: Language Clarification

Q1. In which order will the following expression be computed?

addInt(computeInt()).subtractFloat(computeFloat());
  • addInt, computeInt, subtractFloat, computeFloat
  • computeInt, subtractFloat, computeFloat, addInt
  • computeInt, addInt, computeFloat ,subtractFloat
  • computeFloat, subtractFloat, computeInt, addInt

Q2. Copy Elision is a popular optimisation that avoids creating unnecessary temporary objects.

  • True
  • False

Q3. Which of the following defines prvalue(pure rvalue)?

  • An object that we can move from, which we can reuse. Usually, its lifetime ends soon
  • An expression that has an identity, and which we can take the address of
  • An expression whose evaluation computes the location of an object, bit-field, or function
  • Something without a name, which we cannot take the address of, we can move from such expression

Quiz 2: Templates

Q1. What statement can not be used to deduce parameters Template?

  • Option 1
std::tuple t(1, 2, 3); 
  • Option 2
std::tuple<int,int,int> t(1, 2, 3); 
  • Option 3
std::tuple<char,char> t(a, b, c); 
  • Option 4
std::tuple t(x,y,z);

Q2. Pick up the correct syntax (as per new updates) for using variable number of parameters in a function:

  • Option 1
auto sum(args){..}

template<typename T1, typename... T>
auto sum(T1 s, T... ts) {
    return s + sum(ts...);
}
  • Option 2
template<typename ...Args> sum(Args ...args){
    return (args + ...);
}
  • Option 3
auto sum(args t1, t2, ..){..}

template<typename T1, typename... T>
auto sum(T1 s, T... ts) {
    return s + sum(s,.. ts...);
}
  • Option 4
auto sum(){..}

template<typename T1, typename... T>
auto sum(T1 s, T... ts) {
    return s + sum();
}

Q3. The typename is allowed in C++ 17 rather than class name?

  • true
  • false

Quiz 3: General Language Features

Q1. Have a look at the codes below. Which code shows the new syntax for writing if statements in C++17?

  • Option 1
if(var > 100; auto var = findValue()){...}
  • Option 2
if(auto var = findValue(); var > 100){...}
  • Option 3
int var = findValue();
if(var > 100){...}

Q2. constexpr Lambda functions are constant expressions themselves, but they can invoke methods which are not constexpr.

  • True
  • False

Q3. C++17 introduces a new way of writing nested namespaces. How can we rewrite the code below to fit C++17 standards?

namespace Building {
  namespace Floor {
    namespace Room {
      ...
    }
  }
}
  • Option 1
namespace Building::namespace Floor::namespace Room {
  ...
}
  • Option 2
namespace Room::Floor::Building {
  ...
}
  • Option 3
namespace Building {
  Floor {
    Room {
      ...
    }
  }
}
  • Option 4
namespace Building::Floor::Room {
  ...
}

Quiz 4: Standard Attributes

Q1. Which of the following is NOT true about an Attribute?

  • Is additional information that can be used by the compiler to produce code
  • Might be utilised for optimisation
  • Might be used for some specific code generation
  • Allows you to write less expressive syntax

Q2. A [[fallthrough]] attribute suppresses compiler warnings about unused entities when they are declared with [[maybe_- unused]]

  • True
  • False

Q3. To suppress a warning you can explicitly cast the return value of a function to

  • int
  • string
  • void
  • float

Quiz 5: std::optional

Q1. For an optional variable var, which one of these methods of accessing its value is incorrect?

  • Option 1
*var
  • Option 2
var.value_or(10)
  • Option 3
&var

Q2. An std::optional variable requires more memory than a normal data type variable.

  • True
  • False

Q3. Consider a custom class called myClass. What is the problem with calling the default constructor with an optional wrapper like this:

std::optional<myClass> var{myClass};
  • It takes extra memory as a new temporary object is also created.
  • The null type needs to be defined for custom classes so that optional knows what the empty object looks like.
  • std::optional works for constructors with arguments, not the empty constructor

Quiz 6: std::variant

Q1. Which of the following is NOT a possible use of std::variant?

  • Error handling
  • Finite State Machines
  • As a possible replacement for const std::string& parameter
  • Polymorphism without vtables and inheritance

Q2. A visitor is “a Callable that accepts only a single possible alternative from every variant“.

  • True
  • False

Q3. In the code below why is monostate used?

std::variant<std::monostate, NotSimple, int> okInit;
  • Allows you to create more complex types and pass more parameters
  • Specify which type you want to change/set
  • Used to specify which index you want to change/set
  • Can be used with variants to represent an empty state

Q4. std::visit allows you not only to visit one variant but many in the same call.

  • True
  • False

Quiz 7: std::string_view

Q1. Which of these codes is not the correct way to create a string_view?

  • Option 1
const char* myStr = "A String";
std::string_view sv { myStr };
  • Option 2
std::string_view sv;
sv = {"A", " ", "String"};
  • Option 3
std::string myStr = "Hello String";
std::string_view sv = myStr;
  • Option 4
const char* myStr = "A String";
std::string_view sv { myStr, 3 };

Q2. What will be following code output?

  std::string myStr = "This is a string"; 
  std::string_view sv = myStr;
  auto sv2 = sv.substr(5, 4);
  std::cout << sv2.data(); 
  • is a string
  • This is a string
  • is a
  • out_of_range

Q3. The lifetime of a string_view must never exceed the lifetime of the string-owning object.

  • True
  • False

Quiz 8: String Conversions

Q1. from_chars is a set of overloaded functions: for integral types and floating point types

  • True
  • False

Q2. What is the purpose of std::chars_format fmt in the code below?

std::to_chars_result to_chars(char* first, char* last,
FLOAT_TYPE value,
std::chars_format fmt);
  • Is a set of overloaded functions for integral and floating point types.
  • Allows to specify precision
  • Let’s you specify the output format
  • Holds valuable information about the conversion process

Quiz 9: Parallel STL Algorithms

Q1. What is a parallel_unsequenced_policy?

  • Execution policy type used to indicate that a parallel algorithm’s execution may be parallelized.
  • Execution policy type used to indicate that a parallel algorithm’s execution may be parallelized and vectorized
  • Execution policy type used to indicate that a parallel algorithm’s execution may not be parallelized

Q2. Which of the following is NOT true about the reduce algorithm?

  • Returns the sum of all the elements in a range
  • Applies a function object to the first n elements of a sequence
  • Is a sequential algorithm
  • Similar to std::partial_sum, includes the i-th input element in the i-th sum
Conclusion:

I hope this C++17 in Detail: A Deep Dive Educative Quiz Answers would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published.