Defining and Calling Functions in C
A function packages reusable logic under a name: a return type, a name, a parameter list, and a body. C requires declaration before use — define helpers above main() or write prototypes (signatures ending in ;) up top with bodies later. Calling runs the body with arguments bound to parameters, then resumes after the call.
main() is just a function with a special role as entry point. Splitting programs into small single-purpose functions is the primary tool for taming complexity — C has no classes or namespaces to do it for you.
Signature anatomy
int add(int a, int b) promises two ints in, one int out. The body between braces fulfills it.
Declare before use
The compiler reads top to bottom — declare (prototype) or define every function before its first call.
Call and resume
add(2, 3) runs the body with a=2, b=3; return hands 5 back and execution continues after the call.
void returns nothing
void greet(void) performs an action with no result — callers use it as a bare statement.
#include <stdio.h> int add(int a, int b) { return a + b;} int main(void) { printf("%d\n", add(2, 3)); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.