Notes / C++ / Functions

Functions in C++ — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Functions C++ functions work like C's, but add two powerful features: default arguments (a parameter can have a fallback value) and function overloading (multiple functions can share a name if their parameter lists differ)..

Syntax

syntax
returnType functionName(type param = defaultValue) {
    return value;
}

Example

cpp
#include <iostream>
using namespace std;

int add(int a, int b) {
    return a + b;
}

double add(double a, double b) {
    return a + b;
}

int main() {
    cout << add(2, 3) << endl;
    cout << add(2.5, 3.5) << endl;
    return 0;
}

Output

output5 6

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Be ready to define function overloading precisely: same name, different parameter list, resolved at compile time.
Back to notes Read full lesson →