-
Sends needed data back to main function
-
Data will be used in code inside of main or will send data to another function
-
-
Prototype:
-
Directs compiler to the program defined function
-
Code before void main ( )
-
Syntax:
-
Data type functionName(parameter types);
-
or
-
-
Data type functionName( );
-
-
Parameters:
-
Information needed from main by function is sent in parameters
-
-
-
Calling or invoking a function:
-
Directs program to perform code in function definition
-
Write code in main function – can be repeated as needed
-
Calls for value returning function start with location for return (often a variable from main)
-
Syntax for call:
-
variableName = functionName(variable names);
-
Or
-
-
variableName = functionName( );
-
or send to the screen
-
-
cout << functionName();
-
or send to a file
-
-
outFile << functionName();
-
-
-
User defined definition:
-
Block of code performed when “called” inside of main function
-
Written after end of main function
-
Begins with function header:
-
Header begins with data type that will be returned
-
No semicolon at end of header
-
-
Syntax:
-
Function Header: (no semi-colon)
-
datatype functionName(variable type variableName)
-
or
-
-
datatype functionName( )
-
-
Open curly brace {
-
Block of code that will perform a task
-
Ending with:
-
return variableName;
-
-
-
Close curly brace }
-
-


