Search This Blog

Friday, February 11, 2011

Printing "Hello World" to screen without using a single semicolon in C/C++

When I first encountered this question, I thought it was impossible. However, there are ways to do so. I don't know if the solutions are exploitation of c / c++. Anyway, here are the most common solutions:

#include<iostream>

int main()
{
    if (printf("Hello World \n")) { }
}

Or you can use the while loop like this:

#include<iostream>

int main()
{
    while (printf("Hello World") > 20) { }
}

If you don't think these codes will work, try them out. They are weird but work well in c / c++.

Notice: These don't work in Java. Not sure about other languages, so use them responsibly. After all, this is just for fun :)

No comments:

Post a Comment