C语言的头文件
/*头文件 a.h*/#ifndef A_H#define A_H/** *定义方法,不提供实现*/int add(int a,int b);#endif
/*add.c*/
#include "a.h"/** *实现头文件a中定义的方法 */int add(int a,int b){ return a+b;}
/*main.c*/
#include <stdio.h>#include "a.h" /*若想在程序中调用a.c中的方法只需要包含a.h即可*/int main(){ printf("1+1=%d\n",add(1,1)); return 0;}
题后话:在使用codeblocks 编译时,这些头文件和源文件要放到工程中去编译时才不会报错,否则编译过不去。所以,要测试上面的说法要注意!
页:
[1]