weixin_慕码人8425619
2021-03-07 10:04
#include <stdio.h>
extern void printLine();
static void say()
{
printLine();
printf("I love imooc\n");
printf("good good study!\n");
printf("day day up!\n");
printLine();
}
因为第三行是内部的 外部是*
本人新手,目前是这样理解的,要是不对望大神指点
#include "test.c" //引用test.c文件----#include的作用纯粹就是内容拷贝,运行时被包含文件test.c中的文本将替换源代码文件中的#include 指令;用extern定义say()函数,程序运行时相当于hello.c与test.c中都定义了外部函数say(),而C语言规定不允许有同名的外部函数,所以编译会报错。
不使用#include "test.c"时则需用extern定义say()函数:
hello.c
#include <stdio.h>
//#include "test.c" //引用test.c文件
extern void printLine() //这里定义的方法对吗?
{
printf("**************\n");
}
int main()
{
extern void say();
say();
return 0;
}test.c
#include <stdio.h>
extern void say()
{
extern void printLine();
printLine();
printf("I love imooc\n");
printf("good good study!\n");
printf("day day up!\n");
printLine();
}C语言入门
928197 学习 · 21544 问题
相似问题