Introduction
A function is the single most important tool for organizing a program. It lets you take a block of logic, give it a name, and reuse it as many times as you like — turning a long, repetitive program into a set of small, testable building blocks. Recursion is a special way of solving a problem where a function calls itself to solve a smaller version of the same problem. Scope is the set of rules that decide where in a program a given name (a variable or function) is visible and usable.
For BCS, Bank IT, and IT-officer exams these three ideas appear constantly: MCQs on the difference between parameters and arguments, tracing the output of a recursive factorial or Fibonacci, spotting the base case, counting how many times a function runs, call-by-value vs call-by-reference, the meaning of local vs global variables, and the role of the call stack. If you master this lesson you can answer almost any "what is the output" or "which of the following is true about functions" question.
Learning objectives
- Define a function and explain why functions matter (modularity, reuse, abstraction).
- Distinguish a parameter from an argument, and a function declaration from its definition and call.
- Explain call by value vs call by reference and predict what each does to the caller's data.
- Define recursion, identify the base case and recursive case, and trace a recursive call step by step.
- Explain the call stack, stack frames, and stack overflow.
- Convert simple recursion to iteration and know the trade-offs.
- Define scope and lifetime, and distinguish local, global, static, and block scope.
- Apply the correct terms in exam MCQs with confidence.