Function prototype: Difference between revisions

Content added Content deleted
Line 78: Line 78:
Function prototypes are typically included in a header file at the beginning of a source file prior to functional code. However, this is not enforced by a compiler.
Function prototypes are typically included in a header file at the beginning of a source file prior to functional code. However, this is not enforced by a compiler.


<lang c>int noargs(); /* Declare a function with no arguments that returns an integer */
<lang c>int noargs(void); /* Declare a function with no argument that returns an integer */
int twoargs(int a,int b); /* Declare a function with no arguments that returns an integer */
int twoargs(int a,int b); /* Declare a function with two arguments that returns an integer */
int twoargs(int ,int); /* Parameter names are optional in a prototype definition */
int twoargs(int ,int); /* Parameter names are optional in a prototype definition */
int anyargs(...); /* An ellipsis can be used to declare a function that accepts varargs */
int anyargs(); /* An empty parameter list can be used to declare a function that accepts varargs */
int atleastoneargs(int, ...); /* One mandatory integer argument followed by varargs */</lang>
int atleastoneargs(int, ...); /* One mandatory integer argument followed by varargs */</lang>

=={{header|C++}}==
Function declaration in C++ differs from that in C in some aspect.

<lang cpp>int noargs(); // Declare a function with no arguments that returns an integer
int twoargs(int a,int b); // Declare a function with two arguments that returns an integer
int twoargs(int ,int); // Parameter names are optional in a prototype definition
int anyargs(...); // An ellipsis is used to declare a function that accepts varargs
int atleastoneargs(int, ...); // One mandatory integer argument followed by varargs
template<typename T> T declval(T); //A function template
template<typename ...T> tuple<T...> make_tuple(T...); //Function template using parameter pack (since c++11)
</lang>


=={{header|COBOL}}==
=={{header|COBOL}}==