Ch 8 · Functions · C++

Topic 8 of 13 in C++ — Complete Tutorial (Beginner) — 2 lessons.

Functions, Defaults & Overloading

A function is a named, reusable block of code. In C++ you declare its return type, name, and parameters. C++ adds two handy features: default parameters (a value used when the caller omits an argument) and overloading (several functions sharing a name but differing in parameters, with the compiler picking the right one). These make functions flexible and expressive.

Pass by Value vs Reference

By default, C++ passes a copy of an argument, so changes inside the function do not affect the original. Adding & to a parameter makes it a reference — an alias for the caller's variable — so the function can modify the original directly and avoids copying large data. Use a const reference (const T&) to pass big values efficiently without allowing changes.

All topics in C++ Beginner

  1. Introduction to Programming & C++
  2. Your First C++ Program
  3. Variables & Data Types
  4. Input & Output
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Functions
  9. Vectors & Strings
  10. Classes & Objects
  11. Working with Classes
  12. Exception Handling
  13. Mini-Projects & Practice