What are the advantages of function prototyping in c++?
Answers
Answered by
3
Originally Answered: What is the purpose of a function prototype?
The Function prototype serves the following purposes –
1) It tells the return type of the data that the function will return.
2) It tells the number of arguments passed to the function.
3) It tells the data types of the each of the passed arguments.
4) Also it tells the order in which the arguments are passed to the function.
Therefore essentially, function prototype specifies the input/output interlace to the function i.e. what to give to the function and what to expect from the function.
Prototype of a function is also called signature of the function. If one doesn’t specify the function prototype, the behavior is specific to C standard (either C90 or C99) that the compilers implement. Up to C90 standard, C compilers assumed the return type of the omitted function prototype as int. And this assumption at compiler side may lead to unspecified program behavior. Later C99 standard specified that compilers can no longer assume return type as int. Therefore, C99 became more restrict in type checking of function prototype.
Hope it helps......
The Function prototype serves the following purposes –
1) It tells the return type of the data that the function will return.
2) It tells the number of arguments passed to the function.
3) It tells the data types of the each of the passed arguments.
4) Also it tells the order in which the arguments are passed to the function.
Therefore essentially, function prototype specifies the input/output interlace to the function i.e. what to give to the function and what to expect from the function.
Prototype of a function is also called signature of the function. If one doesn’t specify the function prototype, the behavior is specific to C standard (either C90 or C99) that the compilers implement. Up to C90 standard, C compilers assumed the return type of the omitted function prototype as int. And this assumption at compiler side may lead to unspecified program behavior. Later C99 standard specified that compilers can no longer assume return type as int. Therefore, C99 became more restrict in type checking of function prototype.
Hope it helps......
Answered by
2
Hey !
Advantages of function prototyping:
=> Enables a compiler to carefully compare each use of the function with the prototype to determine whether the function is invoked properly i.e., the number and type of arguments are compared and any wrong number or type of the arguments is reported.
=> Tells the program about the return type .
=> Tells the program the number and type of arguments.
Advantages of function prototyping:
=> Enables a compiler to carefully compare each use of the function with the prototype to determine whether the function is invoked properly i.e., the number and type of arguments are compared and any wrong number or type of the arguments is reported.
=> Tells the program about the return type .
=> Tells the program the number and type of arguments.
Similar questions