10 creative ways to print Hello World in C/CPP and Python

Using Intervee.io, we created a fun challenge that requests them to print “Hello World”, but without using the letter W or any numbers in their code. We posted that challenge in Reddit.

Link to the challenge: https://platform.intervee.io/challengeinfocard/hello_[w09]orld

Link to the posts in Reddit:


After the solvers solved the challenge, they were asked about their experiences.

(173 users tried to solve it, and 148 succeeded in the recommended time without receiving hints from the virtual interviewer)

Only 30% of the solvers were juniors (0-2 years of experience). 70% were with 2+ years.
85% of the solvers that didn’t solve it on time – were juniors.
That means that this challenge was difficult for juniors but easy for seniors. Sounds like an excellent way to check whether a candidate is junior or senior. 

Cool solutions

The most common and trivial one – with the %c specifier
Reminder: the char 87 in ascii is W.

printf("Hello %corld", ++*(char[]){"V"});

printf("Hello %corld", *"V" | *"A");

printf("Hello %corld", *"*" + *"-");

char c = c^c++; 

printf("Hello %corld",c);

printf("Hello %corld", EUSERS);

This was the shortest code.  EUSERS is indeed 87:
Edit: this solution requires adding a specific #include, so maybe it is not the shorter.

Cool c++ solution:

char c = (sizeof(bool)+sizeof(short)) * (sizeof(long) * sizeof(float) - sizeof(char) - sizeof(short));
cout << "Hello " << c << "orld";

It is worth mentioning that the solution is saved as multiple steps, so it’s possible to see how the solver proceeds and not only his final solution.

Super cool Python (Solvers could solve it also in Python) solutions:

from googletrans import Translator
text = 'Hola Mundo!'
translator = Translator()

import hello
# _hellol is a known library that prints hello world. Problem solved.

The “encryption” approach, both in C and C++:

char str[] = "Obkkh'Phukc\n";
char strPtr = str; while (strPtr != '\n') *strPtr++ ^= '\a';
printf("%s", str);

Same approach, in C++:

std::string str = "V_xyz";
char v_x;
for(auto i:str){ v_x=i; break; }
std::cout<<"Hello "<<v_x<<"orld";

Cool cheating solution:

system("echo \"echo Hello World\" > /usr/bin/gcc");

The solver found out that the challenge uses the gcc at /usr/bin/gcc to compile the code, and replaced it with “echo Hello World”. Super nice! Note that every solver gets a different virtual machine so that replacement does not affect other solvers.

Do you have another unique solution? Let me know 🙂

2 thoughts on “10 creative ways to print Hello World in C/CPP and Python”

Leave a Comment

Your email address will not be published. Required fields are marked *