---
title: "C语言的头文件"
author: "ileson"
date: "2011-03-09T19:39:44Z"
tags: []
categories: ["编程语言"]
slug: "c"
draft: false
lastmod: "2012-10-22T16:47:03Z"
id: 949212
url: "https://ileson.iteye.com/blog/949212"
---

/*头文件 a.h*/

```C

#ifndef A_H
#define A_H
/**
 *定义方法，不提供实现 
 */
int add(int a,int b);
#endif

```


/*add.c*/

```C

#include "a.h"
/**
 *实现头文件a中定义的方法
 */
int add(int a,int b){
    return a+b;
}

```


/*main.c*/

```C

#include <stdio.h>
#include "a.h" /*若想在程序中调用a.c中的方法只需要包含a.h即可*/
int main(){
   printf("1+1=%d\n",add(1,1));
   return 0;
}

```


题后话：在使用codeblocks 编译时，这些头文件和源文件要放到工程中去编译时才不会报错，否则编译过不去。所以，要测试上面的说法要注意！