测试时间

问题 #1

Why are named constants often a better choice than literal constants?

问题 #2

Find 3 issues in the following code:

#include <cstdint> // for std::uint8_t
#include <iostream>
 
int main()
{
  std::cout << "How old are you?\n";
 
  std::uint8_t age{};
  std::cin >> age;
 
  std::cout << "Allowed to drive a car in Texas: ";
 
  if (age >= 16)
      std::cout << "Yes";
  else
      std::cout << "No";
 
  std::cout << '.\n';
 
  return 0;
}

Sample desired output:

How old are you?
6
Allowed to drive a car in Texas: No
 
How old are you?
19
Allowed to drive a car in Texas: Yes
 

问题 #3

What are the primary differences between std::string and std::string_view?

What can go wrong when using a std::string_view?

问题 #4

Write a program that asks for the name and age of two people, then prints which person is older.

Here is the sample output from one run of the program:

Enter the name of person #1: John Bacon
Enter the age of John Bacon: 37
Enter the name of person #2: David Jenkins
Enter the age of David Jenkins: 44
David Jenkins (age 44) is older than John Bacon (age 37).
 

问题 #5

In the solution to the above quiz, why can’t variable age1 in main be constexpr?