开发者

Is it possible to write a C program without using header files?

Is it possible to write a C program without using header files? If it is, 开发者_如何学运维how?


Of course:

int main() {
   return 0;
}

Or even:

int printf(const char *format, ... ); // could be copied from stdio.h

int main() {
   printf("Hello, world!\n");
   return 0;
}

The #include directive effectively just includes the header file's content in the source file.


Of course.

A header file is just a file that gets included in some source files, and when you include a file you just copy its content.

You can write any program you want to without any #include, but you'd have to manually put the stuff you need in your source files.


Yes it is possible to write a simple program without header files, but why would you do that ?

Header files are useful to share definitions, constants, functions prototypes, etc between multiple files or modules.


Sure. Because header files written in C. But it's hard.

printf example:

int printf(const char *format, ...);

scanf example:

int scanf(const char *format, ...);

and more...


Absolutely yes, you can even inlinme the function prototype you possibly need in the c file itself


I was trying to write the shortest code possible in c, so i tried removing the header files from source code.To my surprise even a program with printf compiled with just a warning and ran successfully.How does that happen??

main() { printf("Hello World\n"); }


It's possible, but by all means, avoid from not using it if not necessary.


Yes you can wirte a program without #include , but it will increase the complexity of the programmer means user have to write down all the functions manually he want to use.It takes a lot of time and careful attention while write long programs.Yes ,simple program like given above have no problem to write without including any library function call.


#include<"filename"> 

will help you to implement and use the functions present in the file, i.e.

#include< stdio.h>

will help us to use the built functions present in the stdio.h file - printf and scanf

When you dont use #include< stdio.h> in your program , it still will not cause any problems, its only when you may use printf or scanf it may cause the program to generate a warning at the time of compilation (for implicit declaration of function printf.)

More Details on the same , Below link is the screenshot for the same for the printf used without specifying #include<stdio.h>

image

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜