Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
In C++, a function must be known to the compiler before it's called. This is handled by splitting it into declaration (prototype) and definition.
int add(int a, int b);Tells the compiler about the function name, return type, and parameters. Usually goes above main() or in a header file.
int add(int a, int b) {
return a + b;
}The actual implementation of the function logic.
Declarations allow functions to be defined in any order and enable cross-file function calls. It's the "contract" the compiler uses to verify function calls.