CSS Computer Science (Optional) — Paper-I, Section-A, Topic II subtopic. How code is organized into reusable, callable units, and how data moves in and out of them.

Why Use Functions

Anatomy of a Function

int add(int a, int b)   // prototype/signature: return type, name, parameters
{
    int sum = a + b;    // function body
    return sum;         // return statement -- sends a value back to the caller
}

int main()
{
    int result = add(3, 4);   // function call, with arguments 3 and 4
}

Standard Library vs User-Defined Functions

Parameter Passing

void increment(int x) { x++; }   // caller's variable unchanged after this returns