I am just now learning about function prototypes. Can anyone help me answer the folloing questions?
1)I know that function prototypes are useful for avoiding compilation errors. Are there any other advantages of using function prototypes?
2)When designing the placement of a return statement in a function, why is it a good idea to return a value as soon as it is computed?
3)How do we store local declarations in computer memory? Are there any reasons to avoid using local declarations if it is possible to achieve the same result without them?
1. Well function prototypes are there both for the programmer and the compiler.
The compiler can pick up on type errors, and parameter errors.
Libraries are usually already compiled. The header files for that library tell the programmer what functions are avaiable in the library, and return types, parameters etc.
2. This is a matter of opinion. Google c++ return statement
3. Local declarations of functions?? I don't quite get this question. Are you talking about local functions (not allowed in C\C++) or local variables?
Thanks a lot for the help, for Quest.1 and 2
For 3 I acctually ment global declarations and local declarations. What are the differences and where can I use them.....
Actually, you should usually attempt to use local variables so that you can use the same variable name in multiple functions without having to name them differently and possibly confusingly.
Just to further firedraco's point, as a general rule, you should always limit the scope to no more than what is absolutely required. This improves code maintainability.