Master C++

Section quiz

Contents

Contents

Master C++

0 of 235 complete

Section quiz

Your first program

Nine questions on the compiler, the five lines of hello, the errors you have already met on purpose, and reading input.

Questions are shuffled within each part, and so are the answers. You can retake it as often as you like.

0 of 9 answered

Part 1: How a C++ program gets built

Question 1

The compiler reports eighteen errors from one file. What is the best next move?

Question 2

A file compiles with no errors, but the build fails with undefined reference to 'main'. What has gone wrong?

Question 3

What does #include <iostream> actually do?

Question 4

A 60 line program has a mistyped name on line 40. You press run. What happens?

Question 5

The compiler reports main.cpp:6:5: error: expected ';' before 'return'. Line 6 is return 0;, which looks perfectly correct. What is wrong?

Part 2: Output and input

Question 6

A program contains, in this order, std::cout << "red"; then std::cout << "green"; then std::cout << "blue";. What appears on the screen?

Question 7

The input is one line reading Ada Lovelace. The program does std::string s; std::cin >> s;. What is in s afterwards?

Question 8

What does std::cout << "3 + 4"; put on the screen?

Question 9

A program reads a seat count with std::cin >> seats; and then reads a customer name with std::getline(std::cin, name);. The name always comes back empty, and the program never pauses for it. Why?

9 questions left to answer.