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

© 王海江1 中级黑马   /  2014-6-14 20:42  /  1700 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

我记得以前在书上看到说:当调用printf和scanf函数时可以不写#include<stdio.h>,,,,但调用put char、gets等函数时必须写#include<stdio.h>,,,,时这样吗????

6 个回复

倒序浏览
当然不是这样,printf也是库函数,你不写,那printf从哪里来呢?又不是自己写的
这种问题建议楼主直接动手,实践出真理!何必在群里问!多简单,直接敲一个printf就可以了!
回复 使用道具 举报
这个东西在文件包含里面有详细介绍啊,深刻的理解他
回复 使用道具 举报
  1. _CRTIMP size_t __cdecl fwrite(const void *, size_t, size_t, FILE *);
  2. _CRTIMP int __cdecl getc(FILE *);
  3. _CRTIMP int __cdecl getchar(void);
  4. _CRTIMP int __cdecl _getmaxstdio(void);
  5. _CRTIMP char * __cdecl gets(char *);
  6. _CRTIMP int __cdecl _getw(FILE *);
  7. _CRTIMP void __cdecl perror(const char *);
  8. _CRTIMP int __cdecl _pclose(FILE *);
  9. _CRTIMP FILE * __cdecl _popen(const char *, const char *);
  10. _CRTIMP int __cdecl printf(const char *, ...);
  11. _CRTIMP int __cdecl putc(int, FILE *);
  12. _CRTIMP int __cdecl putchar(int);
  13. _CRTIMP int __cdecl puts(const char *);
复制代码


看了一下stdio.h的源码,可以看到 stdio.h函数就是提供输入输出函数的声明的,如果不包含的话,是不能使用诸如printf和scanf这样的输入输出函数的。
回复 使用道具 举报
1.概念:库函数是有C系统提供给用户的不需用户定义,也不用在程序中声明,只需在程序前包含该函数的头文件,即可在程序中调用,如printf、scanf、getchar、gets等均属于此类,所以必须包含头文件才可使用。
2.像楼主类似的问题,可以在x-code中输入输出试一下,实践是检验真理的标准嘛!
回复 使用道具 举报
include stdio.h非必需。stdio.h定义了不少输入输出的标准函数比如说printf,大部分程序都会用上,所以你感觉好像必须有了。

有些程序不需要任何标准输入输出语句,比如说单片机上的程序。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马