Calling a Function

<< Click to Display Table of Contents >>

Navigation:  Concordance Programming Fundamentals > Writing a Function >

Calling a Function

In programming, when you call a function you are actually initiating the function. You are telling the function to begin and perform any tasks.

To call a function

1.Type the name of the function, followed by a list of parameters that the function is expecting.

2.If the function returns a value, be sure to assign that value to a variable.

 

The following example calls multiply_X_by_Y, and assigns the returned value to myValue.

int myValue;

myValue = Multiply_x_by_y(15, 10);

 

In addition, you can place variables in the parameter list. The function call will make a copy of the values stored in the variables, and pass the copied value in through the parameters.

main()

{

   int myValue;

   int valOne;

   int valTwo;

 

   valOne = 10;

   valTwo = 5;

 

   myValue = Multiply_X_by_Y(valOne, valTwo);

}

 

Multiply_X_by_Y(int x, int y)

{

   int z;

   z = x * y;

   return(z);
}