C++ Functions and Structures: A Comprehensive Guide
Classified in Technology
Written on in
English with a size of 6.26 KB
Function Definition
A function definition in C++ consists of the statements that constitute a function. It includes:
- Name: The identifier of the function.
- Parameter List: Variables enclosed in parentheses that hold values passed to the function.
- Body: Statements within curly braces that perform the function's task.
- Return Type: The data type of the value the function returns (e.g.,
int,double,voidif no value is returned).
Function Header
The function header declares the function. It consists of:
- Return Type
- Name
- Parameter List
For example: void evenOrOdd(int num). Note that there is no semicolon at the end of the header.
Function Return Type
- If a function returns a value, the return type must be specified (e.g.,
int main()). - If a function doesn't return