Learnings of the Week [November 17-21, 2008]
In this week, we tackled about the. . .
FUNCTIONS AND STRUCTURED PROGRAMMING
A C program is composed of at least one function definition, that is the main() function. Execution of the program begins with main() and also ends with the main() function. However, a c program can also be composed of other functions aside from the main().
The C program presented in previous slide is composed of 3 functions: the main function, function greet1, and function greet2. Therefore, we can say that we can create a program that is composed of other function aside from the main function. Note that the main() function should always be present in every C program.
FUNCTIONS DEFINED
Functions are the building blocks of C in which all program activity occurs. A function is also called a subprogram or subroutine. It is a part of a C program that performs a task, operation or computation then may return to the calling part of the program. Other functions aside from the main() can only be executed by the programming through a “function call’. Note that the function call is a c statement that is used to call a function to execute C statements found inside the function body.
The general form of the function is:
function_type function_name (parameters list)
{
body of the function;
}
| function_type | - specifies the type of value that the function will return |
| function_name | - is any valid identifier name which will name the function |
| Parameter list | - is a comma separated list of variables that receive the values when the function is called |
| Body of the function | - is composed of valid c statements that the function will execute |
TYPES OF FUNCTIONS
Void Functions - which does not return any value when invoked.
Function that returns a value once invoked.
ACTUAL AND FORMAL PARAMETERS
Actual Parameters are the variables found in the function call whose values will be passed to the formal parameters of the called function.
Formal Parameters are the variables found in the function header that will receive from the actual parameters.
CALL BY VALUE
In the method call by value, the values of the actual parameters are passed to the formal parameters. Changes that happen to the values of the formal parameters inside the function will not affect the values of the actual parameters.
PASS BY VALUE OR CALL BY REFERENCE
The actual parameters also pass their value to the formal parameters. But the changes that happen to the values of the formal parameters inside the function will affect the values of the actual parameters. This is because the actual address of the variables is passed using the address of operator (&) together with the pointer operator (*).
<#include
| sqrt(x) | |
| fabs(x) | - calculates the absolute value of a number |
| ceil(x) | - ceil (11.25) = 12 |
| floor(x) | - floor (11.25) = 11 |
| sin(x) | |
| cos(x) | |
| tan(x) | |
| pow(x) | |
RAE ANGELINE S. PALEN
IV - Rizal


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home