Examples of Function Calls

For example, the declaration of funct is a protoype. When function funct is called, the parameter f is converted to a double, and parameter c is converted to an int.

char * funct (double d, int i);

main
{
   float f;
   char c:

   funct(f, c)  /* f is a double, c is an int */
}

The order in which parameters are evaluated is not specified. Avoid calls such as:

method(sample1, batch.process--, batch.process);

In this example, batch.process-- might be evaluated last, causing the second and third arguments to be passed with the same value.


In the following example, main passes func two values, 5 and 7. The function func receives copies of these values, and accesses them by the identifiers a and b. The function func changes the value of a. When control passes back to main, the actual values of x and y are not changed. The called function func only receives copies of x and y, and not the actual values themselves.

#include <stdio.h>

int main(void)
{
   int x = 5, y = 7;

   func(x, y);
   printf("In main, x = %d   y = %d\n", x, y);
}

void func (int a, int b)
{
   a +=b;
   printf("In func, a = %d   b = %d\n", a, b);
}

This program produces the following output:

In func, a = 12    b = 7
In main, x = 5     y = 7


Functions
Function Calls
Types of Expressions
Operands
lvalues


main() Function
Function Declarations
Function Definitions
Example of the main() Function
Examples of Function Definitions
Examples of Function Declarations