Learn C
#include "functions/functions_basics.h"

Defining and Calling Functions in C

#concept

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.

#how it works
1

Signature anatomy

int add(int a, int b) promises two ints in, one int out. The body between braces fulfills it.

2

Declare before use

The compiler reads top to bottom — declare (prototype) or define every function before its first call.

3

Call and resume

add(2, 3) runs the body with a=2, b=3; return hands 5 back and execution continues after the call.

4

void returns nothing

void greet(void) performs an action with no result — callers use it as a bare statement.

#example
#include <stdio.h>
 
int add(int a, int b) {
return a + b;
}
 
int main(void) {
printf("%d\n", add(2, 3));
return 0;
}
Output
5
1add is defined above main, so its signature is known when the call compiles.
2add(2, 3) binds a=2, b=3, computes 5, and returns it.
3The returned 5 flows into printf's %d and prints.
#use cases
Decomposing main() into named helpers past one screen
Reusing validation, math, and formatting logic from many callers
Declaring prototypes so definition order never constrains design
Testing small pure functions in isolation

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in C yourself — building beats watching.