Bifalgorithm post · Computer science one · Declaration: Prototypes

What information does a C function prototype specify?

What information does a C function prototype specify? (Computer science one · Declaration: Prototypes) — "Typically, the documentation for functions is include…

Ideas in this flowchart

  • Function prototypes and their documentation
  • Documentation is included with the prototype and not repeated with the function definition.
  • This documentation practice follows the Don’t Repeat Yourself (DRY) principle.
  • The examples use a commenting style called doc comments.
  • Doc comments were originally developed for Java and later adopted by many other languages.
  • Examples of documented function prototypes
  • The sum prototype computes the sum of two arguments.
  • The getDistance prototype computes the Euclidean distance between two-dimensional points.
  • The getMonthlyPayment prototype computes a loan’s monthly payment.
  • A prototype specifies the return type first and the function identifier second.
  • Function names follow variable naming rules: they begin with an alphabetic character and may contain alphanumeric characters and underscores.
  • Modern coding conventions usually use lower camel casing for function names.
  • Each function prototype ends with a semicolon.
  • A prototype specifies a function’s signature, not what the function does.
Feed/

What information does a C function prototype specify?

No cover

Channel

Computer science one

1 page

"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."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.