FAQ Part 5: Functions and Scope

How do you define and declare functions?

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

Function declarations (prototypes) can be placed in headers.

What is function overloading?

Function overloading allows multiple functions with the same name but different parameters.

int add(int a, int b);
float add(float a, float b);

What is the scope of a variable?

Scope defines the visibility of a variable:

  • Local: Inside a function/block
  • Global: Outside all functions
  • Static: Retains value between function calls