如何在不使用头文件的情况下编写hello world

Küñ*_*örà 0 c header-files forward-declaration

如何在不使用C中的头文件的情况下编写hello world?

#include<conio.h>
#include<stdio.h>

void main(){

printf("Hello World");
getch();

}
Run Code Online (Sandbox Code Playgroud)

这是带头文件的简单C程序......

  • conio.h - 用于控制台
  • stdio.h- 用于printfscanf

Sou*_*osh 7

您需要头文件主要是因为库函数的原型声明加上任何必要的类型和便于其使用所需的其他宏.它们以头文件的形式提供,以便于重复使用.

在你的情况下,你可以自己编写原型,你应该没事

/*  Prototypes on your own */
int getchar(void);
int printf(const char *format, ...);
int puts(const char *s);

int main(void) {  //this is the prescribed signature for hosted environment
    //printf("Hello World\n");    //not good to use printf if don;t need conversion
    puts("Hello World");
    //getchar();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

应该做得很好.

  • @ user694733它仍然有效.该标准要求所有标准功能都可以使用非宏版本 (4认同)
  • @ user694733这就是为什么标题在那里,以避免所有的麻烦.请注意,我写了_"就好了"_,而不是_"相同"_ :) (4认同)