A functions allows to group the series of steps under single name.
Basic form of the function definition is as follows:
A D V E R T I S E M E N T
output function_name (input_1, input_2, input_3, input_...)
{
// code to execute inside function
}
It is called the function definition as we are defining function. We say that
This is a function called function_name, with the inputs input_1, input_2, etc.,
and whose output is the output. When this function is called, function will execute
a block of code in between the curly braces "{" and "}".
Here is the syntax for the function.
return_type function_name (parameter_1, parameter_2, parameter_3, parameter_...)
{
// code to execute inside function
}
Notice in the place of output, function definition says the return_type. That is
because when we actually are writing the function definition, we will put an return
type there, immediately preceding name of a function. Return type is nothing but
a plain old variable type, such as the int, or double, etc.
Similarly the parameters use the variable types too. If first input to the function is
the int, then first parameter will be something like int myNumber.
When the function is written in C++?
A function will written when there is need to execute certain block of code
more than once, or may even just to separate certain block of code
from rest of the code. For example, to convert the degrees Celsius to the
degrees Fahrenheit we have the following function:
//Sample code for functions in C++
float CtoF(float val)
{
return val *= 1.8 += 32;
}
?
float FtoC(float val)
{
return (val -= 32) /= 1.8;
}
?
int main()
{
float temperature = float();
?
//temperature now is 0, temperature == 0
temperature = 37.5;
?
CtoF(temperature);
?
//temperature is still equal to 37.5
?
temperature = 0;
?
FtoC(temperature);
?
//temperature is still equal to 0
?
CtoF(temperature);
?
//temperature == 0
}
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords Functions, create function, executive functions, user defined function, sql date function,
date function, graph function, algebra functions, vb net functions, precalculus help,
datediff function, sum function, convert function, function key, bash functions, xslt functions,
c function, pl sql functions, table function, life functions, system function,
function of the skin