A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 隔壁老王 中级黑马   /  2015-7-27 22:24  /  637 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


学习目标
1.【掌握】include预处理指令
2.【掌握】多文件开发
3.【了解】认识进制
4.【掌握】进制之间的互相转换
5.【掌握】原码,反码,补码
6.【掌握】位运算
7.【掌握】int类型的修饰符
一、include预处理指令
其实我们早就有接触文件包含这个指令了, 就是#include,它可以将一个文件的全部内容拷贝另一个文件中。
使用语法:
第一种:#include <文件名>
直接到C语言库函数头文件所在的目录中寻找文件
第二种:#include "文件名"
系统会先在源程序当前目录下寻找,若找不到,再到操作系统的path路径中查找,最后才到C语言库函数头文件所在目录中查找
使用注意:
#include指令允许嵌套包含,比如a.h包含b.h,b.h包含c.h,但是不允许递归包含,比如 a.h 包含 b.h,b.h 包含 a.h。下面是错误的用法:


使用#include指令可能导致多次包含同一个头文件,降低编译效率,比如下面的情况:


在one.h中声明了一个one函数;在two.h中包含了one.h,顺便声明了一个two函数。(这里就不写函数的实现了,也就是函数的定义)
假如我想在main.c中使用one和two两个函数,而且有时候我们并不一定知道two.h中包含了one.h,所以可能会这样做:

编译预处理之后main.c的代码是这样的:

[color=rgb(170, 170, 170) !important]1

[color=rgb(170, 170, 170) !important]2

[color=rgb(170, 170, 170) !important]3

[color=rgb(170, 170, 170) !important]4

[color=rgb(170, 170, 170) !important]5

[color=rgb(170, 170, 170) !important]6


[color=rgb(128, 0, 128) !important]void[color=rgb(0, 111, 224) !important] [color=teal !important]one[color=rgb(51, 51, 51) !important]([color=rgb(51, 51, 51) !important])[color=rgb(51, 51, 51) !important];
[color=rgb(128, 0, 128) !important]void[color=rgb(0, 111, 224) !important] [color=teal !important]one[color=rgb(51, 51, 51) !important]([color=rgb(51, 51, 51) !important])[color=rgb(51, 51, 51) !important];
[color=rgb(128, 0, 128) !important]void[color=rgb(0, 111, 224) !important] [color=teal !important]two[color=rgb(51, 51, 51) !important]([color=rgb(51, 51, 51) !important])[color=rgb(51, 51, 51) !important];
[color=rgb(128, 0, 128) !important]int[color=rgb(0, 111, 224) !important] [color=teal !important]main[color=rgb(0, 111, 224) !important] [color=rgb(51, 51, 51) !important]([color=rgb(51, 51, 51) !important])[color=rgb(51, 51, 51) !important]{
[color=rgb(0, 111, 224) !important]    return[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]0[color=rgb(51, 51, 51) !important];
[color=rgb(51, 51, 51) !important]}

3 个回复

正序浏览
老王你好老王再见
回复 使用道具 举报
听说include的路径的查找还有可能是个面试题的
回复 使用道具 举报
本来还想复习一下,没想到看得我眼花缭乱
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马