Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

Is it possible to write a C program without using header files? If it is, how?

like image 939
Yogendera Singh Rautela Avatar asked Aug 26 '26 18:08

Yogendera Singh Rautela


2 Answers

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.

like image 157
Amnon Avatar answered Aug 28 '26 08:08

Amnon


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.

like image 45
peoro Avatar answered Aug 28 '26 09:08

peoro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!