Guided Notes

Functions & Recursion

Defining functions, parameters and return values, declarations (prototypes), scope, header files, and recursion.

Defining functions

Slide 1 / 5

A function groups code under a name:

double area(double width, double height) { return width * height; }

int main(void) { printf("%.1f\n", area(3.0, 4.5)); }

• The return type comes first (void if nothing is returned). • Parameters are local copies of the arguments. • return ends the function and sends a value back. • Small, single-purpose functions make programs easier to read and test.

← Memory Addresses & Pointers