3140 MIDTERM Flashcards

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
Q

What happens to elements in a container if the container is destroyed?

A

The elements are destroyed as well

26
Q

How are dynamically allocated objects destroyed?

A

When the delete operator is applied to a pointer to the object

27
Q

When are temporary objects destroyed?

A

At the end of the full expression that created it (the semi-colon ‘;’)

28
Q

What is a sequence point?

A

The semi-colon at the end of an expression

29
Q

What is the format of a copy constructor?

A

ClassName (const ClassName&);

30
Q

What happens with a copy constructor if the member variable is a pointer?

A

Only the address stored is copied

31
Q

What is it called when a pointers address is copied instead of what it points to?

A

A shallow copy

32
Q

What is the format of a copy assignment?

A

ClassName& operator = (const ClassName&);

33
Q

What is the rule of 3/5?

A

If an object needs a constructor, it likely needs a copy constructor and copy assignment operator

34
Q

What is a move constructor?

A

Moves an object on construction if the source of the value is an unnamed object.

35
Q

What is the format for a move constructor?

A

ClassName(ClassName&&)

36
Q

When is the move constructor not synthesized?

A

If a copy constructor has been written

37
Q

What is the format of a move assignment?

A

ClassName& operator = (ClassName&&);

38
Q

What do smart pointers do?

A

Ensure that the objects to which they point are automatically freed

39
Q

What are the two types of smart pointers?

A
  1. shared_ptr
  2. unique_ptr
40
Q

What is the format for a shared_ptr?

A

shared_ptr<data_type> p;</data_type>

41
Q

What is make_shared()?

A

A function that creates an object with dynamic memory then returns a smart pointer

42
Q

How do shared pointers know to free the object?

A

Reference count goes to zero

43
Q

What doe the operator “new” return?

A

A pointer

44
Q

How does delete work?

A

Must pass a pointer to a dynamically allocated object, then it calls the destructor

45
Q

What is a dangling pointer?

A

When you delete the underlying object a pointer is pointing to but the pointer still represents that memory space

46
Q

What is wrong with:
shared_ptr<int> p1 = new int (42);</int>

A

Shared pointers must be direct initialized

47
Q

How do you test if there are other shared pointers to the same object?

A

unique()

48
Q

What can a default destructor not delete?

A

A pointer