3140 MIDTERM Flashcards

(48 cards)

1
Q

What does specifying a function as “inline” do?

A

The function will (probably) be expanded in the line that it is called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why use inline?

A

It lowers the runtime overhead of calling a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Will a function specified as inline always be evaluated inline?

A

No, the compiler may choose not to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What restrictions are imposed on constexpr functions?

A
  1. Return type and parameter types must be a literal type
  2. It must only have one return statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the compiler do with constexpr?

A

Replace the function with the value if able

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where should inline and constexpr functions be defined?

A

Header files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the 2 steps the compiler takes with classes?

A
  1. Declarations
  2. Function bodies
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Do constructors have a return type?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Can constructors be declares as const?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Can constructors write to const objects?

A

Yes, during construction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a default constructor called in C++?

A

Synthesized Default Constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What was the first programming paradigm?

A

Imperative Programming

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are records in OOP?

A

Structures used to group related data together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What was the first OO language?

A

Simula

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the three pillars of OOP?

A
  1. Encapsulation (Abstraction)
  2. Inheritance
  3. Polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the two parts of encapsulation?

A
  1. Abstraction
  2. Data Hiding
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the 4 access specifiers?

A
  1. Public
  2. Private
  3. Protected
  4. Friend
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is RAII?

A

Resource Allocation Is Initialization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the best practice for initializing an instance of a class?

A

Name n{ };

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What can a constructor with only one parameter be used for?

A

Type Conversion

21
Q

What is constructor delegation?

A

When one constructor calls another constructor

22
Q

What are synthesized methods?

A

Implicitly defined functions in classes under certain circumstances

23
Q

What are the 6 synthesized methods?

A
  1. Default constructor
  2. Destructor
  3. Copy constructor
  4. Move constructor
  5. Copy assignment operator
  6. Move assignment operator
24
Q

When are variables destroyed?

A

When they go out of scope

25
What happens to elements in a container if the container is destroyed?
The elements are destroyed as well
26
How are dynamically allocated objects destroyed?
When the delete operator is applied to a pointer to the object
27
When are temporary objects destroyed?
At the end of the full expression that created it (the semi-colon ';')
28
What is a sequence point?
The semi-colon at the end of an expression
29
What is the format of a copy constructor?
ClassName (const ClassName&);
30
What happens with a copy constructor if the member variable is a pointer?
Only the address stored is copied
31
What is it called when a pointers address is copied instead of what it points to?
A shallow copy
32
What is the format of a copy assignment?
ClassName& operator = (const ClassName&);
33
What is the rule of 3/5?
If an object needs a constructor, it likely needs a copy constructor and copy assignment operator
34
What is a move constructor?
Moves an object on construction if the source of the value is an unnamed object.
35
What is the format for a move constructor?
ClassName(ClassName&&)
36
When is the move constructor not synthesized?
If a copy constructor has been written
37
What is the format of a move assignment?
ClassName& operator = (ClassName&&);
38
What do smart pointers do?
Ensure that the objects to which they point are automatically freed
39
What are the two types of smart pointers?
1. shared_ptr 2. unique_ptr
40
What is the format for a shared_ptr?
shared_ptr p;
41
What is make_shared()?
A function that creates an object with dynamic memory then returns a smart pointer
42
How do shared pointers know to free the object?
Reference count goes to zero
43
What doe the operator "new" return?
A pointer
44
How does delete work?
Must pass a pointer to a dynamically allocated object, then it calls the destructor
45
What is a dangling pointer?
When you delete the underlying object a pointer is pointing to but the pointer still represents that memory space
46
What is wrong with: shared_ptr p1 = new int (42);
Shared pointers must be direct initialized
47
How do you test if there are other shared pointers to the same object?
unique()
48
What can a default destructor not delete?
A pointer