在 C 語言中,當函式在宣告之前呼叫時,會發生什麼事?
如果我們不使用某些函式原型,並且函式體在該函式呼叫語句之後的某個部分中宣告。在這種情況下,編譯器認為預設返回型別為整數。但是,如果函式返回其他型別的返回值,它就會返回錯誤。如果返回型別也是整數,那麼它會良好工作,有時這可能會產生一些警告。
示例程式碼
#include<stdio.h>
main() {
printf("The returned value: %d
", function);
}
char function() {
return 'T'; //return T as character
}輸出
[Error] conflicting types for 'function' [Note] previous implicit declaration of 'function' was here
現在,如果返回型別是整數,那麼它會工作。
示例程式碼
#include<stdio.h>
main() {
printf("The returned value: %d
", function());
}
int function() {
return 86; //return an integer value
}輸出
The returned value: 86
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP