Talk:C Programming/Procedures and functions


 * Added "We then assign x multiplied by x, or x squared, to the variable square_of_x, which is what this function is all about." to the explanation of the first example function - it seemed to miss the point rather without that 86.129.225.142 12:17, 29 Jun 2005 (UTC)


 * Removed a couple of completely incorrect bits. You cannot call a fuction like: foo(void).  The "void" part is correct in a declaration, but not a call.  Also, it's perfectly legal to assign an int to a float.  C allows such conversions without a cast. -- 67.170.85.37 04:00, 3 January 2006 (UTC)

Umm. C has no "built-in" functions. printf comes from the standard library. It is entirely reasonable (though painful) to write a program that doesn't link the standard library.

Bad first example
That first example does not reflect a situation where a function is needed, so it lacks of potential to show readers why functions are important in C programming. In that specific situation, you might prefer to define a variable and use its value twice, since the function has a single outcome. The procedure feature is not actually used.

The first example has two (nested) main functions. Am I missing something? Or is that a mistake?

Variable-length argument lists
The `average` function does not return the expected results. The following code shows you this: int main {

printf("%f\n", average (2, 10, 20)); //15.000000

printf("%f\n", average (7, 1, 100)); //92347288.000000

return 0;

}