C++ References, const and std::string: Beginner Test


This beginner C++ test covers references, const and std::string, the three features that separate everyday C++ from C. Questions check the difference between passing an int by value and by reference, how a reference aliases a variable while a copy has its own storage, why a reference must be initialised and can never be reseated, what a const std::string& parameter guarantees and the compile error you get when you modify it, why std::string::size does not count a terminator, how == compares string contents and why std::cout prints a bool as 1, copies versus references in range-based for loops, which arguments can bind to a non-const reference, and how find and substr take a position and a count. Every code question is a complete program you can compile with g++ in the C/C++ sandbox. The test has 10 multiple-choice questions with correct answers and an explanation for each.

Comments

No comments yet. Be the first to share your thoughts.
10 questions
Beginner
0.0 (0)

Author

Software engineer and the creator of the Bytestark learning platform