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.
What if one doesn’t specify the function prototype?
Output of below kind of programs is generally asked at many places.
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. But to make C99 standard backward compatible, in practice, compilers throw the warning saying that the return type is assumed as int. But they go ahead with compilation. Thus, it becomes the responsibility of programmers to make sure that the assumed function prototype and the actual function type matches.
To avoid all this implementation specifics of C standards, it is best to have function prototype.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Importance of function prototype in C
- How to call function within function in C or C++
- arc function in C
- strtoumax() function in C++
- iswctype() function in C/C++
- putchar() function in C
- c32rtomb() function in C/C++
- c16rtomb() function in C/C++
- wcsrchr() function in C/C++
- wcspbrk() function in C/C++
- mbrtowc() function in C/C++
- strtoimax() function in C++
- wctype() function in C/C++
- Inline function in C
- strcspn() function in C/C++
- strrchr() function in C/C++
- atexit() function in C/C++
- iswxdigit() function in C/C++
- strrev() function in C
- strlwr() function in C