Function Declarations
Learn how to declare functions in C++
We'll cover the following
Declaration of Function in C++
Before we discuss calling functions, we must talk about declarations. Programs written in C++ are executed in logical order from the top down. A statement can only use symbols, or named constructs like functions, that are declared in code that has already been executed. Simply put; the compiler must be aware of the name used to describe a function before that function can be called in the code.
For example, to allow main
to call functions that are defined after the main
function itself in the code, we use forward declarations. A forward declaration tells the compiler that a function exists and what its arguments look like, but the definition of the function will be elsewhere.
The declaration begins much the same as the definition.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy