你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

C语言声明和实现分开例子

2022/8/23 6:20:25

通常将c函数的声明放在头文件,实现放在另一个文件,最后函数被其他文件调用。

一、声明

1 //last.h 
2  
3 #include <stdio.h> 
4  
5 void test1();

二、实现

1 //last.c
2 
3 #include "last.h"
4 
5 void test1(){
6         printf("hello world");
7 }

三、调用

//name.c 

#include "last.h"
int main(){
        test1();
}

四、编译运行

#gcc last.c -c

#gcc last.o name.c -o end

#./end