Lesson 1 Flashcards

Variables, Scope, Functions, Header Files, Conditions and Branches, Logical Expressions, Ternary Operators, Loops and Control Flow, References and Pointers, Dynamic Memory Allocation,Smart Pointers, Classes and Structs, Inheritance, Class Member Visibility, Static in Classes, Mutable, Constructors, Destructors (92 cards)

1
Q

include

A

Pre-processor Directive. Starts with #.

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

int main() { }

A

A special function that runs your main program.

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

I.D.E.

A

Integrated Development Environment

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

system(“PAUSE”);

A

This is a function provided by iostream that is often used to keep your program open until there is an input.

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

Variable

A

A handle to memory somewhere.

Must have a data type when initialized.

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

Declaration

A

Providing something with basic attributes.

It’s type and it’s name.

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

Definition

A

A Declaration and an Assignment

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

Assignment

A

Setting a value. RHS

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

Signature

A

Data type, Name, arguments, argument types, const, static, etc…

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

char

A

1 byte - -127 to 127

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

int

A

4 bytes - -2b to 2b

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

unsigned

A

Same amount of memory but only positive and 0

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

double

A

large number with a decimal

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

bool

A

true or false

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

float

A

number with a decimal

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

Scope

A

Lifetime of an object that dictates visibility most often represented with curly brackets.

Region of a program where the binding is valid.

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

Functions

A

Names code that will be repeated
Syntax Example:
void add(int arg_1, int arg_2) { }

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

When do you make a Function

A

When you find yourself copying code.

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

Header Files

A

Files meant to be #included at compile time.

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

pragma once

A

Windows specific function that Will check to make sure header files are not duplicated at compile time.

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

Reest

A

accelerated garbage

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

Conditions

A
Writing code that only runs if specific prerequisites are met.
Syntax Example:
if(x > 5) {
...run this code...
} else { ..do this..};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Ternary Operators

A

One line conditional assignments
Syntax Example:

int x = (y < 2 && y >= 17 ? 5 : 1);
–if y is less than 2 AND y is greater than or equal to 17 return 5. If not return 1.–

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

Iterator/Iteration

A

Processing through a data container often to allow you to manipulate the data at every index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
continue
skip one iteration
26
break
take out of loop
27
return
ends the function
28
pointer
address in memory int myPtr* = &x;
29
int* ptr = &x; | what is & here?
& is the "address of" operator here
30
int x = 5; int* ptr = &x; *ptr = 1; std::cout << *ptr << std::endl; ^ What is the * here?
* there is the dereference operator here.
31
Reference
Same thing as a pointer except it will never need derefrenced and it can not be null. ``` This is a Function definition that takes in an argument by reference: int myFunc(int &local_var); ```
32
Null
Absolute Zero, invalidated.
33
Dynamic Memory Allocation
This is when you allocate data to a memory address on the heap with a targeted lifespan using the keyword "New". ***You must delete and null the pointer when you finish using this memory address.
34
New
Dynamically Allocating memory on the heap. ***You must delete and null the pointer when you finish using this memory address. int* x = new int;
35
Delete
Keyword used to delete information formerly stored at a specific memory address. delete ptr;
36
Nullptr
When a pointer is set to null. Null is to invalidate, to express intent and avoid error. ptr = nullptr;
37
When do I want to dynamically allocate memory on the heap?
If it's large or you want to control the lifetime of the object. Also if you want to give it global thread access.
38
What are the 2 most commonly used smart pointers?
Unique and Shared
39
What is a smart pointer?
``` A smart pointer is a class wrapped around a raw pointer that deletes itself and is thread and exception safe. Smart pointers can also give your pointer a more clear intent. ```
40
Which library contains standard smart pointers?
41
What are the special attributes of a "Unique" pointer?
Unique pointer takes ownership of a dynamically allocated block of memory which means it will delete and null itself when it falls out of scope or if your program crashes after memory was allocated.
42
What are the special attributes of a a "Shared" pointer?
A shared pointer will keep an internal record of how many instances of it there are and delete and null automatically when the last instance falls out of scope or your program crashes.
43
What is a Class - What is it used for? | What is it's default visibility?
Essentially a namespace wrapper used to organize your code and set limitations and show intent. Visibility is Private by default ``` class myClass { public: ``` private: };
44
What is a Struct - What is it used for? | What is it's default visibility?
Essentially a namespace wrapper used to organize your code and set limitations and show intent. Visibility is Public by default struct myStruct { public: };
45
What are the functional difference in Classes and Structs? | What is the difference in the way Classes and Structs are commonly used?
Other than default visibility there are no functional differences between Classes and Structs. Classes are created to serve as a blueprint to create more instances of the same data type and most commonly are used with polymorphism and inheritance. And Structs are most often used for storage.
46
What is Inheritance?
Inheritance is when a class takes attributes and has visibility of a parent class class child : public myClass { };
47
What is static? | What does that mean in classes?
Static is a keyword that makes the value of a variable stay the across all compile units. In classes this means it will stay the same across all instances of that class.
48
The Const keyword
Const is a declaration that makes the RHS value immutable
49
The Mutable Keyword
Mutable allows a const data type to be mutable.
50
What is a Constructor
A set of instructions specifying exactly how you want a class to be constructed. ``` class myClass { public: myClass() {} }; ```
51
What is a Destructor
Triggered behavior whenever a class is destroyed ``` class myClass { public: myClass() {} }; ```
52
Virtual Keyword
The virtual specifier specifies that a non-static member function is virtual and supports dynamic dispatch. Virtual functions are member functions whose behavior can be overridden in derived classes. As opposed to non-virtual functions, the overridden behavior is preserved even if there is no compile-time information about the actual type of the class. virtual void normalVirtual() {}
53
Pure Virtual Keyword
A virtual method that is enforced. It is used for abstract classes because it will not allow any new instances of the class to be constructed. virtual void pureVirtual() = 0;
54
Polymorphism How does the virtual method know which method to call?
The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. C++ polymorphism means that a call to a member function will cause a different function to be executed depending on which derived class was allocated to be pointed to by the base using a v table.
55
Virtual Destructors
Will make sure the destructor is called in polymorphic instances for the derived destructor. virtual ~myClass() {}
56
Copy Constructor
Special constructor that takes in an instance of it's own type to copy another instance of the same class type. myClass(myClass& other) {}
57
Operator Overloading
When you overwrite or add functionality to symbols in reference to classes and/or structs.
58
The "this" keyword
"this" is a pointer to the current instance that the method is being called on.
59
The dot "." operator
Also known as the access operator this is used to access data members and methods of a class. instance.someMethod();
60
The arrow "->" operator
The arrow operator is used to simultaneously access and dereference a instance of a class. (*instancePtr).someMethod(); is equivalent to instancePtr->someMethod();
61
Member initializer lists
List of initialized variables that comes with the constructor. myClass() : data(0) {}
62
Enum Classes
A class that's only purpose is to assign a set of states to numbers so they can be called later with more ease ``` enum class state { Idle, Walking, Talking, Attacking }; ``` int main() { state s = state::Idle; system("PAUSE"); return 0; }
63
Raw Array
A raw array is a c style data container that can contain elements of the same data type. It is always allocated on the Stack You must know the size at compile time. Tip: Const will make any variable you create known at compile time. int myArray[size];
64
Vectors
C++ style data containers that can contain elements of the same data type. The size of a vector can change dynamically so you do not have to know the size of your vector at compile time. Vector and all of it's features are provided in in std namespace under header std::vector myVector;
65
std::array
A standard array is a standard namespace wrapper around a raw array that is templated to handle the size and data type for you It is always allocated on the Stack You must know the size at compile time. Tip: Const will make any variable you create known at compile time. std: :array and all of it's features are provided in in std namespace under header std: :array myNewArray;
66
std::string
A standard string is a standard namespace wrapper around a c string. It dynamic allocates to the heap included by the string library. which is part of iostream. std::string name = "Josh";
67
"string literals"
string literals are an RHS value string more often known as a temporary or in place. String literals can only be taken in as arguments if they are const because string literals are const. TIP: If you choose to take a string literal argument try to pass by reference to avoid unnecessary overhead. std::string name = "Josh"; Here "Josh" is the RHS value in double quotes which is a string literal.
68
int x = 5; const int* const ptr = &x; What is this?
A constant pointer to a constant integer. Meaning the pointer and the data type are both immutable.
69
Manager Class Pseudo-pattern
This pattern is when you create manager class to abstract away complexity from other classes or the user. It's not necessarily related to inheritance or polymorphism.
70
Facade Pattern
This pattern is when you abstract away complexity from other classes or the user behind a simple interface.
71
Flyweight Pattern
A flyweight pattern is used to centralize heavy object or large data structures that will not change per instance and pointing to them in order to avoid duplication.
72
Game Loop
int main() { ``` while (True) { processInput(); update(); render(); } } ```
73
Factory Pattern
Centralizing responsibility of object allocation to a common class, function, or method.
74
Getters and Setters Pseudo-Pattern
Methods that either return a value or set a value internally in a class.
75
Delta Time Δ
t2 - t1 Delta means difference. Time 2 - Time 1
76
Service Locator Pattern
Centralized place to obtain key classes that you may want to work with. Like an address book. ``` struct Services { PlayerManager* playerManager; SoundManager* soundManager; GraphicsEngine* graphicsEngine; } ```
77
Generic Update Pseudo-Pattern (ΔT)
Method that takes delta time and uses it to update the class.
78
the "Auto" keyword
When defining code you can use auto as the data type to deduce data type automatically from the RHS value/
79
Namespaces
A wrapper to organize your code and prevent name clashes. namespace ax { struct vector{}' } int main() { ax::vector myNewVector; }
80
Constructor Deletion
You can delete any constructor which will prevent you from preforming that constructors expressed task. ``` class test { public: test() = delete; }; ``` int main() { test instance; system("PAUSE"); return 0; }
81
Function Pointers
Pointer to a function used to inject custom code into outside libraries or namespaces that you don't otherwise have access to. And/or to separate task responsibility. bool(*ptr)(int); Here we are instantiating a function pointer that returns a boolean and takes in an integer as an argument. To call the function: ptr(1);
82
Lambdas
A Lambda is an anonymous function that's assigned to a named variable used to take information from one place to another and perform a task without compromising either data bases ownership of specific tasks or the single responsibility principle.
83
Single Responsibility Principle
One of the pillars of software engineering that refers to always striving to make every class, function and so on responsible for a singular task.
84
K.I.S.S.
Keep it simple stupid Software systems work best when they are kept simple. Avoiding unnecessary complexity will make your system more robust, easier to understand, easier to reason about, and easier to extend.
85
D.R.Y.
Don't Repeat Yourself It basically means that you should not write the same code/configuration in multiple places. If you do that, then you’ll have to keep them in sync; and any changes to the code at one place will require changes at other places as well.
86
Y.A.G.N.I.
You Aren’t Gonna Need It It states that you should not introduce things in order to solve a future problem that you don’t have right now. Always implement things when you actually need them. It will help you keep your software lean and simple. It will also save you extra money and effort.
87
S.O.L.I.D.
S - SRP (Single Responsibility Principle) O - OCP (Open Closed Principle) L - LSP (Liskov Substitution Principle) I - ISP (Interface Segregation Principle) D - DIP (Dependency Inversion Principle)
88
Open Closed Principle
When we develop software, we do it in phases. We implement a bunch of functionalities, test it, and then release it to the users. Then we start implementing the next set of functionalities. When we develop new functionalities, the last thing we want is to make changes to the existing functionality that works and is tested. We instead try to build the new functionality on top of the existing functionality. The Open/Closed principle is a facilitator of the above idea. It advises that we should build our functions/classes/modules in such a way that they are open for extension, but closed for modification.
89
Entitys Components Systems
Every entity consists of one or more components which contains data or state. Therefore, the behavior of an entity can be changed at runtime by systems that add, remove or mutate components. This eliminates the ambiguity problems of deep and wide inheritance hierarchies that are difficult to understand, maintain and extend. Common ECS approaches are highly compatible and often combined with data-oriented design techniques.
90
Liskov Substitution Principle
The Liskov Substitution Principle simply means that every child/derived class should be substitutable for their parent/base class without altering the correctness of the program. In other words, the objects of your subclass should behave in the same way as the objects of your superclass. If it looks like a duck, quacks like a duck, but needs batteries - You probably have the wrong abstraction.
91
Interface Segregation Principle
The Interface Segregation Principle states that a client should never be forced to depend on methods it does not use.
92
Dependency Inversion Principle
The Dependency Inversion Principle tries to avoid tight coupling between software modules. It states that High-level modules should not depend on low-level modules, but only on their abstractions. In simple words, It suggests that you should use interfaces instead of concrete implementations wherever possible.