hello world in C without semicolons and without IF/WHILE/FOR statements

Alex Gordon picture Alex Gordon · Nov 10, 2010 · Viewed 21.6k times · Source

My friend says it's possible to write a C program that will print "hello world" without IF/WHILE/FOR and without semicolons. After minimal research I told her it was not possible. Is it possible?

Answer

cdhowie picture cdhowie · Nov 10, 2010
#include <stdio.h>

int main() {
    switch (printf("Hello, world!\n")) {}
}

If your friend says "oh, you can't use switch either," then:

#include <stdio.h>

int main(int argc, char *argv[printf("Hello, world!\n")]) {}