โšก Part 2: C++ Foundations

Master the building blocks of competitive programming in C++. From your first "Hello World" to functions and arrays.

๐Ÿ“š 3 Chapters ยท โฑ๏ธ Estimated 1-2 weeks ยท ๐ŸŽฏ Target: Write and compile C++ programs

Part 2: C++ Foundations

Before you can solve algorithmic problems, you need to speak the language. Part 2 is your crash course in C++ โ€” from the very first program to functions, arrays, and vectors. You'll build the foundational skills needed for all later chapters.

What You'll Learn

ChapterTopicKey Skills
Chapter 2.1Your First C++ ProgramVariables, input/output, compilation
Chapter 2.2Control Flowif/else, loops, break/continue
Chapter 2.3Functions & ArraysReusable code, arrays, vectors

Why C++?

Competitive programmers overwhelmingly choose C++ for two reasons:

  1. Speed โ€” C++ programs run faster than Python or Java, which matters when you have tight time limits (typically 1โ€“2 seconds for up to 10^8 operations)
  2. The STL โ€” C++'s Standard Template Library gives you ready-made implementations of nearly every data structure and algorithm you'll ever need

Note: USACO accepts C++, Java, and Python. But C++ is by far the most common choice among top competitors, and this book focuses on it exclusively.

Tips for Part 2

  • Type the code yourself. Don't copy-paste. Your fingers need to learn the syntax.
  • Break things. Deliberately introduce errors and see what happens. Reading compiler errors is a skill.
  • Run every example. Seeing output appear on screen cements understanding far better than just reading.

Let's dive in!