哪里錯(cuò)了啊
#include <stdio.h>
#include "test.c" ? //引用test.c文件
extern void printLine() ? ? //這里定義的方法對(duì)嗎?
{
? ?printf("**************\n"); ??
}
int main()
{
? ? say();
? ? return 0;
}
#include <stdio.h>
#include "test.c" ? //引用test.c文件
extern void printLine() ? ? //這里定義的方法對(duì)嗎?
{
? ?printf("**************\n"); ??
}
int main()
{
? ? say();
? ? return 0;
}
2015-12-15
舉報(bào)
2016-01-22
補(bǔ)充:extern的主要作用不在于定義外部變量或函數(shù),而在于引用定義,如果在其他編譯器中去掉#include”test.c",不然會(huì)出現(xiàn)重定義(例如visual studio)。
2016-01-22
因?yàn)槲募ello.c的printLine()函數(shù)和test.c中的say()函數(shù)是被相互引用的,因此這兩個(gè)函數(shù)都應(yīng)為外部函數(shù),在兩個(gè)文件中都必須聲明引用。所以小編的答案是錯(cuò)誤的!具體代碼如下:
hello.c文件中:
#include <stdio.h>
#include "test.c"?? //引用test.c文件
extern void say();
void printLine()???? //這里定義的方法對(duì)嗎?
{
?? printf("**************\n");??
}
int main()
{
??? say();
??? return 0;
}
test.c文件中:
#include <stdio.h>
extern void printLine();
void say(){
??? printLine();
??? printf("I love imooc\n");
??? printf("good good study!\n");
??? printf("day day up!\n");
??? printLine();
}
2016-01-01
答案到底是什么????氣死人了,也不把答案寫出來(lái),明明和圖片一樣的
2015-12-16
這樣寫也算是可以編譯通過(guò)的。 ?不過(guò)本站最近判斷答案正誤的功能有問(wèn)題。
但是:這樣的代碼仍是有問(wèn)題的! ?實(shí)際使用中絕對(duì)不要寫這樣的代碼!!
具體原因請(qǐng)看這里我的回答:http://idcbgp.cn/qadetail/105343