C++ Flashcards
How should one always give arguments to a function if possible?
as const reference
one line if statement
“expression” ? “command if true” : “command if false”
what should you always check when creating new functions?
const correctness
what is a static member variable?
A variable which belongs not to the instance but to the class -> multiple instances access the same value
what is :: called?
scope resolution operator -> then searches global namespace
If you do not specify the access modifier in a class, are it’s members private, protected or public?
private
what is a std::map?
A container, that stores key-value pairs. Keys must be unique (otherwise the old entry is overwritten). A map is sorted through the keys through the < operator, which can also be provided.
what are std::vector and std::list?
both are containers
vector: elements in one block of memory, easy to add and remove elements at end, not so easy to insert, …
list: indirect adressing -> good for insertion, slower for iteration
what important std containers are there?
vector, list, map, multimap, queue, stack, deque, set, array, …
what is the extern keyword?
it says, that a variable is defined in another translation context
how does one define a C++ macro?
define “macroname” “code”
- not recommended in modern C++
How do I declare a variable that stores the address of another?
varA = &varB;
what is * called in C++? How can it be read?
Dereference operator
“value pointed to by”
what is & called in C++? How can it be read?
2 meanings:
1. Address-of operator when used in expression
“address of”
2. In declaration: part of identifier, denotes a reference
“is a reference to”
How does one declare a reference in C++?
“type” & “reference name” = var;