The C compiler reads code from top to bottom. main() — if you write a function's definition below it, you need to declare the function's declaration/prototype above first.
c
#include <stdio.h>
// Function declaration
int add(int a, int b);
int main() {
int result = add(5, 3);
printf("Result: %d", result);
return 0;
}
// Function definition
int add(int a, int b) {
return a + b;
}int add(int a, int b); tells the compiler ahead of time, "a function like this will show up later." The definition is where you write what the function actually does.
You should see
Result: 8Info
Keep the return type, parameter types, and order matching between the declaration and the definition.