C++ Basics Study Notes
Original beginner notes for reviewing core programming concepts. No personal, school, or
textbook content included.
1. Program Structure
A basic C++ program usually includes a header, a main function, statements, and return 0.
#include gives access to cout and cin.
main() is where the program starts running.
2. Variables and Data Types
A variable is a named storage spot for a value.
int stores whole numbers. double stores decimals.
char stores one character. string stores text. bool stores true or false.
Use clear names like totalCost, not mystery garbage like x1 unless it is temporary.
3. Input and Output
cout prints information to the screen.
cin reads input from the user.
Use prompts so the user knows what to enter. Programs that expect mind-reading are bad
programs.
4. If Statements
Use if, else if, and else when the program needs to make a decision.
Common comparison operators: ==, !=, <, >, <=, >=.
Do not confuse = assignment with == comparison.
5. Loops
while loop: repeats while a condition is true.
for loop: best when you know how many times to repeat.
Every loop needs a way to end. Infinite loops are usually caused by forgetting to update the
counter or condition.
6. Functions
A function is a reusable block of code that performs one job.
Good functions have clear names and avoid doing too many unrelated things.
Parameters are inputs. A return value is the result sent back.
7. Arrays and Vectors
An array stores multiple values of the same type in order.
Indexing starts at 0, so the first item is items[0].
vector is usually easier than a fixed-size array because it can grow.
8. Debugging Basics
Use breakpoints to pause the program at a specific line.
Use Step Over to move one line at a time.
Use the Watch or Locals window to inspect variable values.
Do not guess for 30 minutes when the debugger can show the problem in 30 seconds.
9. Common Beginner Errors
Missing semicolon at the end of a statement.
Using a variable before giving it a value.
Integer division when a decimal result was expected.
Off-by-one loops, such as stopping one item too early or too late.
Reading only the last compiler error instead of the first real one.
10. Simple Problem-Solving Plan
11. Write what the program needs to do in plain English.
12. Identify inputs, calculations, and outputs.
13. Build one small piece at a time.
14. Test after every working piece.
15. Commit or save a backup before making big changes.