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

通常将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

posted @ 2022-08-23 05:59  该改改了  阅读(59)  评论(0)    收藏  举报