C++ Fundamentals Including C++ 17 Flashcards
What does “shortcutting” refer to for the && and || operators?
If the result can be determined after evaluating only the first argument, the second will not be evaluated. (Related Clip: Comparisons)
A member function should be marked as const…
… when you first write it, unless it changes a member variable. (Related Clip: Member Functions)
Who makes the decision about adding new features to the C++ language?
An International Standards Organization committee. (Related Clip: Standardization)
Which of these statements about references and polymorphism is correct?
- Only const references are polymorphic.
- References support polymorphism more strongly than pointers do.
- References do not support polymorphism.
- References support polymorphism in the same way as pointers.
-References support polymorphism in the same way as pointers. (Related Clip: References and Inheritance)
What does the break statement mean in a while loop?
Control should exit the loop and continue after it. (Related Clip: While)
What does this line of code do?
std::cout «_space;“Type your name” «_space;std::endl;
Prints “Type your name” (without the quotes) on the screen and moves the cursor down one line. (Related Clip: Demo: Visual Studio Hello World)
Why would any programmer create an object on the free store, also called the heap?
So that the memory can stay in scope after the creating function has ended. (Related Clip: The Free Store)
When moving data of one type into a variable of another type, when do checks on the coversion validity occur?
When your code is compiled. (Related Clip: Demo: Fundamental Types)
If you want to be sure that a developer doesn’t forget to do something, such as closing a file or connection, how can you make sure it gets done?
Put the closing call into the destructor for a class representing the file or connection. (Related Clip: Scope)
A template may count on the types you us it with to implement a particular member function or operator overload. Which technique will not help you to discover the constraints on your type?
- Reading documentation for the template
- Understanding the template error messages when you try to use it
- Reading the source code of the template
- Looking at the constraints in the declaration of the template.
-Looking at the constraints in the declaration of the template. (Related Clip: Template Specialization)
If you declare a function but do not implement it, and code tries to call it, what kind of build error will occur?
Linker error. (Related Clip: Demo: Understanding Error Messages)
After this loop, what is the value of y?
int y = 0; for (int i = 0; i<5; i = i + 1) { y = y + i; }
10 (Related Clip: For)
When your code relies on classes and functions in a namespace, the best way to minimize your typing while preserving your program’s intent is to:
- add using statements referring to the entire namespace, e.g. using namespace std;
- always type the full name including the namespace, e.g. std::cout , whenever referring to the name
- You should not use code form a different namespace
- add using statements referring to the specific name within the namespace, e.g. using std::cout;
-add using statements referring to the specific name within the namespace, e.g. using std::cout; (Related Clip: Demo: Namespaces)
If you write a class with a virtual function in it, what other function should be marked as virtual?
The destructor (Related Clip: Demo: Indirection and Inheritance)
If you delcare an integer pointer like this:
int const * p;
Then attempt to compile these two lines:
p = &something; *p = 2;
Will they compile?
The first, which changes p, will. The second, which dereferences p, will not. (Related Clip: Const with Indirection)