Table of contents
1.
Introduction
2.
Implicit return type int in C
3.
Example
3.1.
Code 1
3.2.
Code 2
4.
Frequently Asked Questions
4.1.
What happens if we do not mention a return type in C?
4.2.
How to get rid of the implicit int rule?
4.3.
What is implicit type conversion?
5.
Conclusion
Last Updated: Mar 27, 2024

Implicit return type int in C

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In this blog, we will discuss Implicit return type ‘int’ in C. First, we will learn what Implicit return type is, and then we will move on to some coding examples of implicit return type in C that will help us understand the concept better.

You can also read about the jump statement, C Static Function

Must Read Passing Arrays to Function in C

Implicit return type int in C

If a function has no return type, the return type is assumed to be int. If no return type is specified, no error will be generated. But this was allowed only till C89. From C99 Standard, if we don’t determine the return type, we cannot execute the function.

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 problemstop 100 SQL problemsresources, 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!"

Live masterclass