Skip to content
Home » How to Write C++ Program Without Header File using extern

How to Write C++ Program Without Header File using extern

Learn about How to Write C++ Program Without Header File using extern in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

As in C language, we cant directly declare printf function and hence we declare printf() function using extern keyword. The extern keyword tells the compiler that the printf function’s declaration is somewhere in C. As a result, the compiler will locate the printf declaration file and incorporate it into our program.

How to Write C++ Program Without Header File using extern

extern "C"
{
   int printf(const char *format, …);
}
int main()
{
   printf("Hello, World!\n");
   return 0;
}

Hello, World!

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
How to Write C Program Without Header File
C Program to Get Process ID and Parent Process ID

Tags: