Function:
One of the building blocks of C++
- The function “main()” is most import function in a program, because the “main()” function is the starting point of the program.
- The main advantage of using function is reusability of code and reduces the size of the program, because a function can be called for multiple numbers of times.
Function prototype:
The function prototype is a declaration of a function which is used to represent the return type of the function, number of arguments passed and the data type used in the function.
- It is same as the function header but it should be terminated with the semicolon.
- It should be declared previous to the “main()” function.
Example for function prototype:
void display();
In the above example, the function “display()” has the return type “void” and it holds the semicolon at the end.
Function header:
The function header is the part of the function definition which holds the return type of the function, function name and the parameter list.
- Semicolon should not be given at the end and the function body should be followed after the function header.
Example for function header:
void display()
In the above example, the function “display()” holds the return type and it does not have a semicolon at the end.
Function call:
The statement which causes the function to execute is referred as function call.
- The function is called by its function name and the return type should not be specified before the function call.
- The semicolon should be given at the end of the function name.
Example for function call:
display();
In the above example, the function “display()” does not have the return type and it holds the semicolon at the end.
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Starting Out with C++: Early Objects
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education