Words of Wisdom:

"Gonzalo es Joto. Mendez" - Chocolate_delight

Functions

  • Date Submitted: 12/01/2011 05:04 AM
  • Flesch-Kincaid Score: 54.2 
  • Words: 629
  • Essay Grade: no grades
  • Report this Essay
Functions

Before reading this tutorial you should have knowledge of pointers.

Functions are building blocks of the programs. They make the programs more modular and easy to read and manage. All C++ programs must contain the function main( ). The execution of the program starts from the function main( ). A C++ program can contain any number of functions according to the needs. The general form of the function is: -

return_type   function_name(parameter list)
{
            body of the function

}

The function of consists of two parts function header and function body. The function header is:-

            return_type   function_name(parameter list)

The return_type specifies the type of the data the function returns. The return_type can be void which means function does not return any data type. The function_name is the name of the function. The name of the function should begin with the alphabet or underscore. The parameter list consists of variables separated with comma along with their data types. The parameter list could be empty which means the function do not contain any parameters. The parameter list should contain both data type and name of the variable. For example,

            int factorial(int n, float j)

is the function header of the function factorial. The return type is of integer which means function should return data of type integer. The parameter list contains two variables n and j of type integer and float respectively. The body of the function performs the computations.


Function Declaration

A function declaration is made by declaring the return type of the function, name of the function and the data types of the parameters of the function.   A function declaration is same as the declaration of the variable. The function declaration is always terminated by the semicolon. A call to the function cannot be made unless it is declared. The general form of the declaration is:-

return_type...

Comments

Express your owns thoughts and ideas on this essay by writing a grade and/or critique.

  1. No comments