Search courses, chapters, or pages...
Build the smallest C/C++ program with `main`, braces, statements, semicolons, and a return code. Recognize where the CPU starts running your code and where each instruction belongs.
Use what you learned in the previous lesson to solve real-world problems.
Choose between `int`, `size_t`, `float`, `double`, and `bool` for simple numeric work. Predict how a variable’s type changes what values it can safely hold.
Check what you understood with a short quiz.
Trace how assignment, arithmetic operators, and compound updates like `+=` change a value step by step. Notice common surprises such as integer division dropping the fractional part.
Use `std::cout` or `printf` to inspect values while a program runs. Read printed output as evidence of what your variables actually contain.
Use `if`, `else`, comparison operators, and logical operators to choose between two paths. Reason through which block runs for a given set of values.
Write a `for` loop when you know how many times work should repeat. Trace the initializer, condition, body, and update in the order the CPU executes them.
Write a `while` loop when repetition depends on a condition becoming false. Identify the update that must happen inside the loop so it eventually stops.
Check loop bounds with zero-based indexes and the `i < n` pattern. Spot why `<= n` often reads or writes one element past the end.
Create a fixed-size C-style array and access elements with indexes starting at zero. Connect each index to one stored value and recognize what an out-of-range index means.
Use `std::vector` for host-side arrays that know their own size and can grow. Practice `size()`, indexing, and `data()` so vector storage can still work with pointer-based APIs later.
Fill, scale, copy, or sum an array by visiting one element per loop iteration. Match each loop index to the input and output element it should touch.
Define a function with parameters, call it with arguments, and use its return value. Separate the reusable calculation inside the function from the code that asks for the result.
Compare returning one result with changing a value through a reference or pointer parameter. Decide when a function should produce a new value and when it should update storage supplied by the caller.
Write a function that receives `T* data` and a count, then loops over the elements safely. Treat the pointer as the start of the array and the length as the rule that keeps access in bounds.
Use `&` to get a variable’s memory address and `*` to read or write the value a pointer refers to. Trace the difference between the pointer variable and the data it points at.
Relate `array[i]`, `*(array + i)`, and `p + i` to the same contiguous storage. Reason about how pointer arithmetic moves by elements, not raw byte counts in your source code.
Track when local variables, arrays, and pointed-to data stop being valid. Recognize dangling pointers, `nullptr`, and the risk of using an address after its storage is gone.
Allocate an array whose size is known only at runtime, then release it correctly with the matching cleanup operation. Compare manual allocation with the safer default of using `std::vector` when possible.
Mark function inputs as `const` when they should not be changed. Use const-correct parameters to make read-only data clear and catch accidental writes at compile time.
Compile a single source file with `g++` or `clang++`, choose a C++ standard flag, and run the produced executable. Connect the command you type to the source file and output program it creates.
Distinguish errors caused by bad syntax or types from linker errors caused by missing function definitions. Use the wording of the message to decide whether to fix code structure or missing build inputs.
Read an error message by file name, line number, error kind, and nearby code. Fix the first real error before chasing later messages that may only be side effects.
Turn on warnings such as `-Wall` and `-Wextra` to catch risky code before it fails. Treat messages about uninitialized values, conversions, and signed/unsigned comparisons as useful debugging clues.
Recognize crashes, out-of-bounds access, and uninitialized reads as runtime problems even when compilation succeeds. Shrink the input and print key values to find the line where memory first goes wrong.
Review this chapter with practice based on your mistakes.