【学习笔记】【C语言】文件的包含

一、基本概念

#include,它可以将一个文件的全部内容拷贝另一个文件中。

二、一般形式

1.第1种形式#include <文件名>
直接到C语言库函数头文件所在的目录中寻找文件
 
2.第2种形式 #include "文件名"
系统会先在源程序当前目录下寻找,若找不到,再到操作系统的path路径中查找,最后才到C语言库函数头文件所在目录中查找

三、使用注意

#include指令允许嵌套包含,比如a.h包含b.h,b.h包含c.h,但是不允许递归包含,比如 a.h 包含 b.h,b.h 包含 a.h。

四、代码

1.

.h文件

1 #ifndef LISI_H
2 #define LISI_H
3 
4 int sum(int a, int b);
5 
6 
7 #endif

.c文件

int sum(int a, int b)
{
    return a + b;
}

2.

.h文件

1 #ifndef WANGWU_H
2 #define WANGWU_H
3 int minus(int a, int b);
4 #endif

.c文件

 1 /*
 2  1.<>表示系统自带的文件,""表示自定义的文件
 3  2.不允许循环包含,比如a.h包含b.h,b.h又包含a.h
 4  */
 5 
 6 #include "lisi.h"
 7 #include "wangwu.h"
 8 
 9 #include <stdio.h>
10 
11 int main()
12 {
13     int c = sum(10, 19);
14     
15     printf("c is %d
", c);
16     
17     return 0;
18 }
 
原文地址:https://www.cnblogs.com/dssf/p/4619954.html