Lesson 4 of 8Article15 min
Functions in C
C uses function prototypes to declare signatures before use. This helps the compiler validate argument and return types.
Function declarations and definitions
C uses function prototypes to declare signatures before use. This helps the compiler validate argument and return types.
Prototype and implementation
#include <stdio.h>
int add(int a, int b); // prototype
int main(void) {
printf("%d\n", add(4, 5));
return 0;
}
int add(int a, int b) {
return a + b;
}Pass by value understanding
- C passes arguments by value by default.
- Use pointers when a function must modify caller data.
- Keep function responsibilities narrow and testable.