Вы находитесь на странице: 1из 4

CRIS ANN B.

RODRIGO

BSCS IC

1.) Function definition

~~~~~~an activity or purpose natural to or intended for a person or thing.

"bridges perform the function of providing access across water"

~~~~~~a relationship or expression involving one or more variables.

"the function (bx + c)"

~~~~~~a thing dependent on another factor or factors.

2.) General Format of a Function Definition

~~~~function_name is the name of the function (which must also be the name of the m-file it is in)

return_value is the name of the output.

parameters are the names of the inputs, separated by commas

3). A. Return Type

~~~~The return type of a function establishes the size and type of the value returned by the function and
corresponds to the type-specifier in the syntax

~~~~The return type given in the function definition must match the return type in declarations of the
function elsewhere in the program. A function returns a value when a return statement containing an
expression is executed. The expression is evaluated, converted to the return value type if necessary, and
returned to the point at which the function was called. If a function is declared with return type void, a
return statement containing an expression generates a warning and the expression is not evaluated.

B. Function name

~~~~A Function object's read-only name property indicates the function's name as speified when it was
created, or it may be rather anonymous or ''(an empty string) for functions created anonymously

C. Paramete
~~~~a numerical or other measurable factor forming one of a set that defines a system or sets the
conditions of its operation.

"the transmission will not let you downshift unless your speed is within the lower gear's parameters"

D. Function Body

~~~~A function body is a compound statement containing the statements that specify what the function
does.

4.) Function call by Value in C

~~~~The call by value method of passing arguments to a function copies the actual value of an argument
into the formal parameter of the function. In this case, changes made to the parameter inside the
function have no effect on the argument. By default, C programming uses call by value to pass
arguments.

Function Call By Reference?

~~~~~Before we discuss function call by reference, lets understand the terminologies that we will use
while explaining this:

Actual parameters: The parameters that appear in function calls.

Formal parameters: The parameters that appear in function declarations.

For example: We have a function declaration like this:

int sum(int a, int b);

The a and b parameters are formal parameters.

We are calling the function like this:

int s = sum(10, 20); //Here 10 and 20 are actual parameters

or

int s = sum(n1, n2); //Here n1 and n2 are actual parameters

In this guide, we will discuss function call by reference method. If you want to read call by value method
then refer this guide: function call by value.

Lets get back to the point.

~~~~When we call a function by passing the addresses of actual parameters then this way of calling the
function is known as call by reference. In call by reference, the operation performed on formal
parameters, affects the value of actual parameters because all the operations performed on the value
stored in the address of actual parameters. It may sound confusing first but the following example would
clear your doubts.

Example of Function call by Reference

#include <stdio.h>

void increment(int *var)

/* Although we are performing the increment on variable

* var, however the var is a pointer that holds the address

* of variable num, which means the increment is actually done

* on the address where value of num is stored.

*/

*var = *var+1;

int main()

int num=20;

/* This way of calling the function is known as call by

* reference. Instead of passing the variable num, we are

* passing the address of variable num

*/

increment(&num);

printf("Value of num is: %d", num);

return 0;

Output:
Value of num is: 21

Вам также может понравиться