C++ Flashcards

1
Q

Union

A

Similar to a structure

All members share same memory

Only one member can be defined at a time

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

Typedef

A

New name for existing data type

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

Reference

A

Alias for another variable

Can’t be reassigned

Doesn’t require dereference (*) operator to access data

Can’t hold null value

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

New

A

Calls constructors

Returns exact datatype

Initializes memory

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

List VS Array

A

Lists don’t have fixed size

Lists require more memory (addresses)

Lists are allocated dynamically

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

Malloc

A

No constructors, just allocates a certain amount of memory

Returns a void pointer

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

Virtual Function

A

Function that can be overridden in sub-classes

Can include a definition

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

Pure virtual Function

A

Virtual function with no definition

Makes base class abstract

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

Abstraction

A

Showing only necessary details

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

Encapsulation

A

Grouping data and code together

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

Inheritance

A

Deriving properties from a base class

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

Multiple Inheritance

A

Inheriting properties from multiple classes

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

Virtual Inheritance

A

Making sure that only one copy of a class is include in an inheritance hierarchy that uses multiple inheritance

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

Polymorphism

A

Multiple forms of the same thing

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

Compile Time polymorphism

A

Function Overloading
Operator Overloading

“Early Binding”

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

Run Time polymorphism

A

Function Overriding
Virtual Functions

“Late Binding”

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

Classes

A

User defined Datatypes

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

Object

A

Instance of a class

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

Constructor

A

Initializes an object

Function in a class

There are no virtual constructors

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

Default constructor

A

Constructor with no parameters or arguments.

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

Parameterized Constructor

A

Constructor with parameters

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

Copy Constructor

A

Member function that initializes on object using another object of the same class

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

Three types of constructors

A

Default

Parameterized

Copy

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

Destructor

A

Deletes an object when it goes out of scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Virtual Destructor
When an object goes out of scope, this makes sure the derived class's destructor is called first, followed by the base class's destructor. Invoked when destroying an derived object using a base class pointer
25
Base Object and Derived Object
A base object pointer can point to a derived object
26
Pointer Incrementation
Pointers will increment by the amount of bytes that the type occupies - aka next memory location Same thing goes for adding integers to pointers, it will move by the integer * num_bytes_of_type
27
Void Pointers
Can store any data type but needs to be cast before dereferencing
28
Pointer Comparison
Equal if they point to the same location Relational comparisons also work based on addresses, only meaningful when they point to the same array
29
delete
Deallocates memory
30
delete[]
Used to deallocate memory from every object in an array
31
Friend Class
Can access both the protected and private variables of the classes where it is declared a friend
32
Friend Function
Can access the private and protected members of a class where it is declared a friend Often used to overload binary operators Defined outside of the class Not inherited by derived classes
33
Access Modifiers
Private Public Protected
34
Inline Functions
Suggest to the compiler to put the code inline instead of generating a function call Can make code run faster For simple functions
35
Abstract Class
Has a pure virtual function Cannot be instantiated
36
Static Variables in Functions
Retains its value across function calls Initialized to 0 unless an explicit value is provided
37
Static Variables in classes
Shared across all objects of a class Initialized to 0 unless an explicit value is provided
38
Static Member Function
Cannot access non-static members Can be called without an object
39
Static Global
Scope is the file Initialized to 0 unless an explicit value is provided
40
Volatile
Indicates that a variable can be changed by external process (they have access to that same memory) Keeps the compiler from making optimizations that could potentially miss a change
41
Storage Class
Defines lifetime and visibility of a variable or function - some of these are auto extern static register mutable
42
mutable specifier
Declares a class member mutable even if the object is declared constant
43
auto
Used to declare a variable with a complex type in a straightforward fashion Compilation time increases but run time does not
44
namespace
Organize named items that would otherwise be global into smaller scopes
45
void
Indicates a function returns nothing
46
Shallow Copy
New structure has reference addresses to the original elements Only pointer addresses are copied
47
Deep Copy
Elements are duplicated
48
this pointer
reference the current instance of an object
49
Template
Allows functions and classes to operate on different data types
50
Functor
Class that acts like a function Overrides the () operator Main purpose is to allow the "function" to have a state
51
52
Iterator
Points toward an element in an STL container Used to traverse elements in a container
53
Container
Classes like vector or stack used to expand array capabilities
54
Time Complexity of deletes or insertions in the middle of a vector
O(N-M) at M index
55
Typically sorting algorithm time complexity
O(NlogN)
56
Pair data type
Tuple, but with only two values
57
List Underlying Data Structure
A doubly linked list Non contiguous storage, no random access
58
Binary Search Tree Search Time Complexity
O(logN)
59
Multiset
Set that allows duplicate value
60
Set underlying data structure
Binary Search Tree (Red Black)
61
Unordered set underlying data structure
Hash table
62
Multi-Map
Map that has multiple values for each key
63
Heap Data Structure
Tree Based data structure that satisfies the heap property Heap Property - certain ordering rules of the tree Used for priority queues, etc
64
Dangling Pointer
Pointer that was pointing to a valid memory location, but that memory has since been taken from the program
65
Unique Pointer
Wrapper Class Automatically deallocate memory when it is no longer needed. This happens when the pointer goes out of scope Copying is disallowed, move semantics are used instead
66
Shared Pointer
Allows multiple pointers to point to the same memory, and it is only deallocated when all pointers go out of scope Each pointer increases the reference count Reference count is kept in the control block, which is stored alongside the managed resource in the heap
67
Weak Pointer
Observer pointer of another smart pointer's memory Does not increment reference count Breaks circular dependencies of shared pointers
68
Lambda Functions
Anonymous functions Useful for short, one time use functions In-Line functions
69
join function
Tells the current thread to wait for the indicated thread to end before finishing
70
Race Conditions
When multiple threads access and modify shared data concurrently
71
Deadlocks
When two or more threads are waiting on each other to release resources
72
Starvation
Some threads may never get CPU time due to other higher priority threads taking up cpu space
73
Threading Determinism
Threaded programs do NOT run deterministically May run in a different order each time
74
Thread Lock
Indicating that only one thread may run on a certain part of the program at a time Mutex library
75
Shared Thread Lock
Lock that allows multiple readers but only one writer
76
l-value
Refers to a memory location Persists beyond a single expression Can be on both the left and right sides of an assignment operator
77
r-value
Temporary value that does not have a persistent memory address
78
Stack Memory
Stores local variables Memory Allocated here when a function is called Memory deallocated when function goes out of scope Memory size is predetermined
79
Heap Memory
Used for dynamic memory allocation Used with the keywords new and malloc Memory persists until it is released
80
Text Memory
Executable Code of the Program
81
Data Segment Memory
Global and static variables Two parts, initialized and uninitialized
82
Move Semantics
Transfers ownership of resources from one object to another The object itself isn't moved
83
Forward
A function used to pass on function arguments wheel preserving their original value category (r-value or l-value) Keeps the program from making unneccessary copies
84
Interface
Class with only pure virtual functions
85
Const class methods
Methods that do not modify state
86
How protect against object copying
Deleting the copy constructor
87
Map Underlying Data Structure
Red Black Tree (Self balancing tree to guarantee access efficiency)
88
Unordered Map Underlying Data Structure
Hash Table
89
Vector Underlying Data Structure
Dynamic Array
90
Deque Underlying Data Structure
Dynamic Array
91
Priority Queue Underlying Data Structure
Binary Heap
92
Stack Underlying Data Structure
Deque, Dynamic Array
93
Queue Underlying Data Structure
Deque, Dynamic Array
94
Atomic Types in C++
Wrapper for data types that ensures that all operations are done in a manner that is indivisible This means multiple threads can't be doing different parts of the same operation at the same time
95
constexpr
Keyword that indicates that a function or expression can be evaluated at compile time
96
static_assert
Can check to make sure an expression is correct during compile time
97
Struct
Like a class but defaults to public access Typically used for more simple data structures
98
Explicit
Prevents implicit type conversions for constructors
99
RAII
Resource Acquisition is Initialization Basically proper memory management
100
Iterators
Objects that allow sequential element access to a container
101
Function Pointers
Pointers that store a function address Allow dynamic function calls
102
Async Functions
More abstraction than threads Less control then threads They return a future, which is just the results from the async function Typically don't block
103
Thread Pool
Initialize a fixed number of threads Tasks are put in a queue, idle threads will execute them Condition variable - lets idle threads know there is a task available
104
Template Specialization
Allows custom behavior for certain datatypes that overrides the general template
105
Non-Type Template Parameters
On type of taking a type, templates can also take constant values as additional parameters
106
Variadic Templates
Templates that take any number of arguments
107