User-defined Functions — Passing Information into Functions

Review of variables:  where they are declared matters:

Review the cls.c program from 01-13.

Information is passed into functions by the parameter list, part of why you need the function prototype before main().  If you do not provide a prototype, C will assume that all of the parameters are ints.  These are actually local variables into which the values are copied from the calling program.  This is referred to "pass by value".  Consequently changes made to variables in the function do not affect the variables in the calling program, and names used in the function for the parameters are completely unrelated to the names used in the calling program.

The easiest way to generate the prototype is simply to copy the first line of the function to the top and put a semicolon after it.

#include <stdio.h>

void testing(int a, int b, int c);     // prototype

int main()
   testing(1, 2, 3);
   return 0;

void testing(int a, int b, int c)
   printf(" . . . %d . . . %d . . . %d . . . \n", a, b, c);

Expanded version of the above:  testing.txt   testing.c  testing.exe