8 questions. Covers Fall-through on purpose.
Questions 1 to 5 of 8
cpp #include <iostream> using namespace std; int main() { int level = 2; int discount = 0; switch (level) { case 3: discount += 10; [[fallthrough]]; case 2: discount += 5; [[fallthrough]]; case 1: discount += 2; break; default: break; } cout << "discount: " << discount << "%\n"; }
cpp #include <iostream> using namespace std; int main() { int code = 200; switch (code) { case 200: cout << "OK\n"; case 404: cout << "Not found\n"; break; case 500: cout << "Server error\n"; break; default: cout << "Other\n"; break; } }
cpp #include <iostream> #include <map> #include <string> using namespace std; int main() { map<string, int> prices = {{"apple", 30}}; int tea = prices["tea"]; cout << tea << " " << prices.size() << "\n"; }
std::map
prices.find("tea")
prices.end()
prices["tea"]
[]
prices["tea"] = 0
prices.size()
switch (command)
command
std::string
==
case
switch
default:
char
5 question(s) left on this page.