Print \\\"Hello World\\\" in C/C++ without using header files



In C/C++, we use the header files for accessing functions such as int, char, string, etc. The printf() function of C is also a built-in function that is declared in the "stdio.h" header file and it is used to print any kind of data on the console.

C to Print "Hello World" without Header Files

The Hello World is the given string that is used in the printf() to get the output. Make sure you don't have any headers to print the result. So, use an argument like (const char *text, ...) that solves the problem.

Syntax

Below is the syntax that must be used in a C program to print the string without the need for header files:

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

Here,

  • const char * : The first parameter is a pointer to a constant character string.

Example

This is the basic C program to display "Hello World" without using header files.

int printf(const char *text, ...);
int main() {
   printf( "Hello World" );
   return 0;
}

Output

The above program produces the following result:

Hello World

C++ to Print "Hello World" without Header Files

In C++, we cannot print the "Hello World" string without header files. It takes the reference of C to print the result. Here, we are going to use a function named syscall() which is written in C but not in C++, and it takes one required argument (number), and then the variable number of arguments (?). This, this helps to get the result.

Syntax

Its syntax is as follows:

syscall(int_val_1, int_val_2, str_name, int_val_3)

Here,

  • syscall(): The syscall() function is part of the Linux operating system that makes direct requests to the kernel. This makes the between interaction hardware and users.
  • int_val_1: This is syscall number for write.
  • int_val_2: This is a file descriptor which is just an integer number used by the operating system to identify open files.
  • str_name: This is pointer name for messaging.
  • int_val_3: This represent the number of bytes.

Example

Following is an example of C++ program that shows the usage of printing "Hello World" without using header files.

extern "C" long syscall(long number, ...);

int main() {
    const char* msg = "Hello World
"; syscall(1, 1, msg, 12); syscall(60, 0); return 0; }

Output

The above program produces the following result:

Hello World
Updated on: 2025-04-21T18:02:10+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements