Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Implicit return type int in C
In C, if a function is declared without an explicit return type, the compiler implicitly assumes the return type to be int. This behavior was allowed in older C standards (C89/C90) but is deprecated and not recommended. The C99 standard requires explicit return types for all functions.
Syntax
function_name(parameters) {
/* Function body */
return value; /* Implicitly returns int */
}
Example: Implicit Return Type
Here's an example demonstrating implicit return type behavior −
#include <stdio.h>
my_function(int x) {
return x * 2;
}
int main(void) {
printf("Value is: %d<br>", my_function(10));
return 0;
}
Value is: 20
Comparison: Implicit vs Explicit
| Approach | Example | Standard Compliance |
|---|---|---|
| Implicit int | my_function(int x) { return x; } |
C89/C90 only |
| Explicit int | int my_function(int x) { return x; } |
All C standards |
Key Points
- Modern C compilers may issue warnings for functions without explicit return types
- Always specify return types explicitly for better code readability and portability
- The
main()function should also have an explicitintreturn type
Conclusion
While implicit int return types were allowed in older C standards, modern programming practice requires explicit return type declarations. Always specify return types explicitly for better code clarity and standards compliance.
Advertisements
