Programming in C

(Barry) #1
454 Appendix A C Language Summary

omitted Outside Anywhere within Constant This
any BLOCK the file or by expressions declaration
other files that only can appear in
contain only one
appropriate place;
declarations variable is
initialized at
the start of
program
execution;
default value
is 0
Inside a BLOCK (See auto) (See auto) defaults to
auto

7.0 Functions


This section summarizes the syntax and operation of functions.

7.1 Function Definition


The general format for declaring a function definition is as follows:
returnType name( type1 param1, type2 param2,... )
{
variableDeclarations

programStatement
programStatement
...
return expression;
}
The function called nameis defined, which returns a value of type returnTypeand has
formal parameters param1,param2,....param1is declared to be of type type1,
param2is declared to be of type type2, and so on.
Local variables are typically declared at the beginning of the function, but that’s not
required.They can be declared anywhere, in which case their access is limited to state-
ments appearing after their declaration in the function.
If the function does not return a value,returnTypeis specified as void.
If just voidis specified inside the parentheses, the function takes no arguments. If ...
is used as the last (or only) parameter in the list, the function takes a variable number of
arguments, as in

Ta ble A.6 Continued
If Storage And Variable Then it can be And can be
Class is is declared referenced initialized with Comments

20 0672326663 AppA 6/10/04 2:01 PM Page 454

Free download pdf