Example
Let us look at an example to understand better how the implicit return type works.
Code 1
#include <stdio.h>
fun(int x)
{
return x*x;
}
int main(void)
{
printf("%d", fun(5));
return 0;
}

You can also try this code with Online C Compiler
Run Code
Output
25

You can also try this code with Online C Compiler
Run Code
In this example, we have used an implicit return type without mentioning the return type.
Code 2
#include<stdio.h>
my_function(int x) {
return x * 2;
}
main(void) {
printf("Value is: %d", my_function(50));
}

You can also try this code with Online C Compiler
Run Code
Output
Value is: 50

You can also try this code with Online C Compiler
Run Code
We have used an implicit return type int without mentioning the return type in this example.
Also Read About, Sum of Digits in C, Tribonacci Series and Short int in C Programming
Must Read what is storage class in c and Decision Making in C
Frequently Asked Questions
What happens if we do not mention a return type in C?
If we don't provide a return type in C, the compiler uses int as an implicit return type. Even if the return type is int, the C99 standard does not allow it to be removed. This was permitted in the C89 standard. Except for a few style C++ compilers like Turbo C++, the above code is invalid in C++.
How to get rid of the implicit int rule?
The current ISO C standard, issued in 2011, disables the "implicit int" rule and requires an explicit statement for any function called. Compilers don't consistently enforce this by default, but you should be able to and should request more strict warnings.
What is implicit type conversion?
The compiler performs implicit type conversions when the operands are of different data types. The compiler automatically transforms smaller data types into more significant data types. Finally, the expression above evaluates to a 'double' value.
Conclusion
This article has discussed the implicit return type int in C and examples. If you want to learn about new emerging technology like Augmented Reality and Virtual Reality, do visit Snake Game and if you're going to participate in contests, please see Contests.
Refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc.
Refer to the links problems, top 100 SQL problems, resources, and mock tests to enhance your knowledge.
For placement preparations, visit interview experiences and interview bundle.
We hope that this blog has helped you in enhancing your knowledge. If you liked this article, please give it a thumbs up!
"Happy Coding!"