Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
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.
Q1. In which order will the following expression be computed?
addInt(computeInt()).subtractFloat(computeFloat());
Q2. Copy Elision is a popular optimisation that avoids creating unnecessary temporary objects.
Q3. Which of the following defines prvalue(pure rvalue)?
Q1. What statement can not be used to deduce parameters Template?
std::tuple t(1, 2, 3);
std::tuple<int,int,int> t(1, 2, 3);
std::tuple<char,char> t(a, b, c);
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:
auto sum(args){..}
template<typename T1, typename... T>
auto sum(T1 s, T... ts) {
return s + sum(ts...);
}
template<typename ...Args> sum(Args ...args){
return (args + ...);
}
auto sum(args t1, t2, ..){..}
template<typename T1, typename... T>
auto sum(T1 s, T... ts) {
return s + sum(s,.. ts...);
}
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?
Q1. Have a look at the codes below. Which code shows the new syntax for writing if
statements in C++17?
if(var > 100; auto var = findValue()){...}
if(auto var = findValue(); var > 100){...}
int var = findValue();
if(var > 100){...}
Q2. constexpr Lambda functions are constant expressions themselves, but they can invoke methods which are not constexpr.
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 {
...
}
}
}
namespace Building::namespace Floor::namespace Room {
...
}
namespace Room::Floor::Building {
...
}
namespace Building {
Floor {
Room {
...
}
}
}
namespace Building::Floor::Room {
...
}
Q1. Which of the following is NOT true about an Attribute?
Q2. A [[fallthrough]]
attribute suppresses compiler warnings about unused entities when they are declared with [[maybe_- unused]]
Q3. To suppress a warning you can explicitly cast the return value of a function to
int
string
void
float
Q1. For an optional variable var
, which one of these methods of accessing its value is incorrect?
*var
var.value_or(10)
&var
Q2. An std::optional
variable requires more memory than a normal data type variable.
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};
optional
knows what the empty object looks like.std::optional
works for constructors with arguments, not the empty constructorQ1. Which of the following is NOT a possible use of std::variant?
Q2. A visitor is “a Callable that accepts only a single possible alternative from every variant“.
Q3. In the code below why is monostate
used?
std::variant<std::monostate, NotSimple, int> okInit;
Q4. std::visit
allows you not only to visit one variant but many in the same call.
Q1. Which of these codes is not the correct way to create a string_view
?
const char* myStr = "A String";
std::string_view sv { myStr };
std::string_view sv;
sv = {"A", " ", "String"};
std::string myStr = "Hello String";
std::string_view sv = myStr;
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();
Q3. The lifetime of a string_view
must never exceed the lifetime of the string-owning object.
Q1. from_chars
is a set of overloaded functions: for integral types and floating point types
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);
Q1. What is a parallel_unsequenced_policy?
Q2. Which of the following is NOT true about the reduce
algorithm?
std::partial_sum
, includes the i-th input element in the i-th sumI 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 >>