Home > Backend Development > C++ > In C language, what happens if a function is called before it is declared?

In C language, what happens if a function is called before it is declared?

WBOY
Release: 2023-08-27 19:21:06
forward
1138 people have browsed it

In C language, what happens if a function is called before it is declared?

If we do not use some function prototypes, and the function body is declared in a certain part after the statement that calls the function. In this case, the compiler assumes that the default return type is integer. But if the function returns a value of another type, an error will be returned. This works fine if the return type is also an integer, it may sometimes generate some warnings.

Sample Code

#include<stdio.h>
main() {
   printf("The returned value: %d</p><p>", function);
}
char function() {
   return &#39;T&#39;; //return T as character
}
Copy after login

Output

[Error] conflicting types for &#39;function&#39;
[Note] previous implicit declaration of &#39;function&#39; was here
Copy after login

Now if the return type is integer then it will work.

Sample code

#include<stdio.h>
main() {
   printf("The returned value: %d</p><p>", function());
}
int function() {
   return 86; //return an integer value
}
Copy after login

Output

The returned value: 86
Copy after login

The above is the detailed content of In C language, what happens if a function is called before it is declared?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template