課程
/后端開發(fā)
/C
/C語言入門
hello.c和test.c的代碼都正確,為什么沒輸出
2015-11-20
源自:C語言入門 5-13
正在回答
補(bǔ)充:extern的主要作用不在于定義外部變量或函數(shù),而在于引用定義,如果在其他編譯器中去掉#include”test.c",不然會(huì)出現(xiàn)重定義(例如visual studio)。
因?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()???? //這里定義的方法對嗎?{?? 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();}
#include <stdio.h>
extern void printLine() ? ?
{
? ?printf("**************\n"); ??
}
int main()
{ ?
? ? printLine();
? ? printf("I love imooc\n");
? ? printf("good good study!\n");
? ? printf("day day up!\n");
}?
me too
我也是
我這面也是一樣情況,提交正確,顯示不出來,刷新也試了
大頭不敗
舉報(bào)
C語言入門視頻教程,帶你進(jìn)入編程世界的必修課-C語言
3 回答代碼輸入不了,為什么?
1 回答為什么輸出不對?
2 回答為什么過了而沒有輸出
3 回答為什么不對,輸出不對么
1 回答為什么提交代碼,不在右側(cè)輸出文字了呢?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
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()???? //這里定義的方法對嗎?
{
?? 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();
}
2015-12-02
#include <stdio.h>
extern void printLine() ? ?
{
? ?printf("**************\n"); ??
}
int main()
{ ?
? ? printLine();
? ? printf("I love imooc\n");
? ? printf("good good study!\n");
? ? printf("day day up!\n");
? ? printLine();
}?
2015-12-01
me too
2015-11-26
我也是
2015-11-21
我這面也是一樣情況,提交正確,顯示不出來,刷新也試了