12.13 — In and out parameters

A function and its caller communicate with each other via two mechanisms: parameters and return values. When a function is called, the caller provides arguments, which the function receives via its parameters. These arguments can be passed by value, reference, or address. Typically, we’ll pass arguments by value or by …

13.11 — Struct miscellany

Structs with program-defined members In C++, structs (and classes) can have members that are other program-defined types. There are two ways to do this. First, we can define one program-defined type (in the global scope) and then use it as a member of another program-defined type: #include <iostream> struct Employee …

8.4 — Constexpr if statements

Normally, the conditional of an if-statement is evaluated at runtime. However, consider the case where the conditional is a constant expression, such as in the following example: #include <iostream> int main() { constexpr double gravity{ 9.8 }; // reminder: low-precision floating point literals of the same type can be tested …

10.4 — Narrowing conversions, list initialization, and constexpr initializers

In the previous lesson (), we covered numeric conversions, which cover a wide range of different type conversions between fundamental types. Narrowing conversions In C++, a is a potentially unsafe numeric conversion where the destination type may not be able to hold all the values of the source type. The …

5.5 — Constant expressions

In lesson , we introduced expressions. By default, expressions evaluate at runtime. And in some cases, they must do so: std::cin >> x; std::cout << 5 << ‘\n’; Because input and output can’t be performed at compile time, the expressions above are required to evaluate at runtime. In prior lesson …