What if one doesn’t specify the function prototype?
The output of the program listed below is frequently asked.
Example 1
int main()
{
func();
getchar();
return 0;
}
void func()
{
printf("func is called");
}

You can also try this code with Online C Compiler
Run Code
Output
abc.c: In function 'main':
abc.c:4:5: warning: implicit declaration of function 'func' [-Wimplicit-function-declaration]
4 | func();
| ^~~~
abc.c: At top level:
abc.c:8:6: warning: conflicting types for 'func'
8 | void func()
| ^~~~
abc.c:4:5: note: previous implicit declaration of 'func' was here
4 | func();
| ^~~~
func is called

You can also try this code with Online C Compiler
Run Code
If the function prototype is not specified, the behavior is limited to the C standard (C90 or C99) that the compilers implement. Until the C90 standard, C compilers believed the missing function prototype's return type was int. And this compiler assumption may result in unspecified program behavior.
Compilers can no longer presume that the return type is int, according to the C99 standard. As a result, type verification of function prototypes became more constrained in C99. In practice, compilers issue a warning that the return type is presumed to be int to keep the C99 standard backward compatible. However, they continue to compile. As a result, programmers are responsible for ensuring that the presumed function prototype and the actual function type are identical.
It is better to have a function prototype to avoid all of these implementation details of C standards.
So a better program would be:
Example 2
#include <stdio.h>
void func();
int main()
{
func();
getchar();
return 0;
}
void func()
{
printf("func is called");
}

You can also try this code with Online C Compiler
Run Code
Output
func is called

You can also try this code with Online C Compiler
Run Code
Also see, Short int in C Programming
FAQs
What are function prototypes and what is its purpose in C++?
A function prototype is a pre-declaration in C and C++ of a function, including its name, parameters, and return type. This makes type checking more reliable for the compiler.
Is a function prototype necessary?
It is not needed, but not using prototypes is bad practice. The compiler can use prototypes to make sure you're calling the function appropriately (using the right number and type of parameters).
How does a function prototype differ from a function definition?
A function definition defines how the function performs what it does (the "implementation"), whereas a function prototype only provides its interface, that is, what data types flow in and out of it.
Read Also - Difference between argument and parameter
Conclusion
In this article, we have extensively discussed the function prototypes and their purpose. We discussed the cases when the function prototype is not declared with examples.
We hope that this blog has helped you enhance your knowledge of the function prototypes in C and if you would like to learn more about C, check out our articles C Archives.
Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc; you must look at the problems, interview experiences, and interview bundle for placement preparations.
Nevertheless, you may consider our paid courses to give your career an edge over others!
Do upvote our blogs if you find them helpful and engaging!
Happy Learning!