C++ Fundamentals Including C++ 17 Flashcards
(32 cards)
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)
When you use a template function in your code, the work of stamping out the version of the function you need is done when?
at compile-and-link time. (Related Clip: Templates)
Which of these is the correct sequence when constructing an object that is an instance of a derived class?
- The derived constructor runs and then the base constructor
- The base constructor runs and then the derived constructor.
- Only the derived constructor runs.
- All the initializers run and then the derived constructor.
- The derived constructor must call the base constructor to make it run.
-The base constructor runs and then the derived constructor. (Related Clip: Demo: Inheritance)
Building in C++ involves compiling and linking. What is the difference between them?
Each source file is individually compiled and the results are linked together into a single output file. (Related Clip: Building)
Templates allow you to write code once, and use it for any type, such as int, Employee, or Person. What important C++ feature do they retain while working across type?
Type safety (Related Clip: Template Classes)
include
What does this line of code do?
Makes the string class in the Standard Library available to your code. (Related Clip: Introduction)
How do you indicate that a C++ function, other than a constructor or destructor, is like a subroutine, not returning a value.
Use the return type of void. (Related Clip: Demo: Member Functions)
If I delcare two integers like this:
int const a = 10; const int b = 10;
In what way are a and b different in ther const-ness?
There is no difference other than style. (Related Clip: Const After or Before?)
Two fo the three special functions referred to in the Rule of Three are the copy constructor and the copy assignment operator. For a class called Person these would be
Person::Person(Person const& p)
and
Person::operator=(Person const& p)
What is the third?
The destructor.
Person::~Person()
(Related Clip: Manual Memory Management)
Which of these is a fundamental type in C++?
- date
- object
- string
- boolean
-boolean (Related Clip: Fundamental Types)