Concept
What information does a C function prototype specify?
ComputerScienceOne / Declaration: Prototypes
"Typically, the documentation for functions is included with the prototype but is not repeated with the function definition. This is a principle known as Don’t Repeat Yourself (DRY). Consider the following examples. In these examples we use a commenting style known as “doc comments.” This style was originally developed for Java but has since been adopted by many other languages.\n\n/**\n\n* Computes the sum of the two arguments.\n\n*/\n\nint sum(int a, int b);\n\n/**\n\n* Computes the Euclidean distance between the 2-D points,\n\n* (x1,y1) and (x2,y2).\n\n*/\n\ndouble getDistance(double x1, double y1, double x2, double y2);\n\n/**\n\n* Computes a monthly payment for a loan with the given\n\n* principle at the given APR (annual percentage rate) which\n\n* is to be repaid over the given number of terms (usually\n\n* months).\n\n*/\n\ndouble getMonthlyPayment(double principle, double apr, int terms);\n\nIn each of these, the return type is the first thing specified. The function identifier (name) is then specified. Function names must follow the same naming rules as variables: they must begin with an alphabetic character and may contain alphanumeric characters as well as underscores. Using modern coding conventions we usually name functions using lower camel casing. Each prototype ends with a semicolon. Further, prototypes do not specify what the function does, they only specify its signature."
Related Ideas
- How do header and source files organize functions in C?ComputerScienceOne · Calling Functions
- What is labeled on page 135?ComputerScienceOne · A function declaration (prototype) in the C programming language with
- What capabilities and constraints do functions have in C?ComputerScienceOne · Declaration: Prototypes
- How are void functions defined in C?ComputerScienceOne · Void Functions
- How do you call functions in C?ComputerScienceOne · Organizing Functions
- How do C functions return values to the calling function?ComputerScienceOne · Void Functions
- How do you declare variables in C?ComputerScienceOne · Declaration & Assignment
- How can pointers be used to pass variables by reference?ComputerScienceOne · Passing By Reference