LS> Forgive the beginner question but why do you declare the
LS> function names before main{} and then list the functions?
Well, I think that in C function prototypes (delaration of
the function name and the types in parameters closed by a semicolon)
are optional as long as the function you're calling PRECEDES using
or "calling" the function. It's like Turbo Pascal's "FORWARD"
declaration of procedures and functions that may be used in some
other function appearing before it in order. I think that C++
REQUIRES prototypes but I'll let the pros expound on that. I'm just
following the "safe" process of making certain the compiler will
flag any attempt to misuse or mismatch functions in actual use. The
function declaration is listed PRIOR to main() and always ends with
a semicolon. Also, the actual variables themselves do not have to
appear in the declaration, only the types thus function_name(int
int); would be a model of a declaration. Then, one is free to
"define" (function definition) the function anywhere else in the
program (in C++ I THINK it can even be within main() but I'm not
sure. The definition would look like this: function_name(int a,
int b) without a semicolon at the end and following it would then
be the code for the function between braces, of course.
While I'm at it, I should confess that in these initial
efforts I'm probably wrong in going for all global variables instead
of giving each function its own variables. I'm going to have to
sort that out pretty quickly. Somebody will probably let me know
that real quick.
Actually, I posted the program in order to spark criticism
and discussion for the benefit of us novices and beginners.
Sincerely,
Frank
--- PPoint 2.03
---------------
* Origin: Maybe in 5,000 years - frankmas@juno.com (1:396/45.12)
|