# 45C Reading Quiz Conceptual Review
## Reading Quiz 1
1. Output of `gradeCalculation`
- The code outputs 'A' due to basic conditional logic rules
2. "Output of Line 12"
- The code outputs `Pointer p points to 0` since the value of `nullptr` in C++ is `0`
3. "Value of `5/2`"
- The value of `5/2` is `2`, since C++ performs integer floor division
4. "`int courseCode = 35760`"
- This message is both an *initialization* and *declaration*, since it declares the variable `courseCode`, and initializes it to that value
5. "type of `A[3]`"
- In C++, if an array is initialized with {}, all of those elements take the type of the array
6. "NOT array of 3 integers"
- In C++, initializing an array with more "elements" than you define default-initializes them to zero.
- Always, the memory right outside of the array is unpredictable, and if you do just `int d[6];`, then all the memory in the array is unpredictable
7. `char` is defined as `' '` (self-explanatory)
8. array of `double` named `A` inside body
- This one is pretty basic, just remember:
- When arrays are globally initalized, they get 0 *automatically* as their default value. That doesn't happen in this case, and it is instead unpredictable.
9. Line 7 Output
- `&var` returns the *reference* to `var`, which is the direct address in memory that may vary each time the program runs
10. `0123456789 ` output is self-explanatory
11. `aBool` output
- `true` is defined as `0` and anything but `0` is defined as `false` in C++. If you set a value of type `bool` (the keyword for `boolean`) to anything that isn't 0, it is automatically counted as `false`
- On the other hand, if you say `bool var = !0`, it is `false`, and if you say `bool var = !#` where `# != 0`, then it is true
12. Whenever you index out of the bounds of an array, you will be accessing random memory that does not belong to the array (and maybe the program)
13. Outputting a pointer directly will give you a hex code such as `0x7ffc1156dbdc`
14. Same as the `double A[N]` question, but now the array is declared as a global variable. See RQ1[8]
15. `&` gives a memory address in C++, while `*` either declares something as a pointer, or *dereferences* a pointer
16. Array length is counted as 1...n, but you index from 0...(n-1)
## Reading Quiz 2
1. `class C` output
- Constructors and Destructors in C++ are defined as such:
```cpp=
class C {
public:
C() {} // this is a constructor
~C() {} // this is a destructor
}
```
- Objects have a "lifecycle"
- They are born (allocated and constructed), live, and die (destructed and deallocated)
- You cannot stop construction and destruction
- Whenever an object is initialized or goes out of scope, it is constructed and destructed, respectively, unless this is done manually during heap allocation with `new`
2. `const` Symbolic Constants
- All symbolic constants in C++ should be defined as ALL_CAPS and have a `const` reference, whether that's before *or* after the type declaration
```cpp=
const double PI = ...;
double const PI = ...;
// both are valid!
```
3. `lvalues` and `rvalues`
- `lvalues` are values that ... TBD COMING SOON