tempest in a teacup

the pointless musings of a strange recluse

The answer to the programming problem I posted

Well, AN answer, at any rate. Click through if you want to see it, but hold off if you want to try it out for yourself.

#include <stdio.h>

int printreverse(char* string) {
    return (*string) && (printreverse(string+1) | printf("%c", *string));
}

The basic idea (to use logical operators to short-circuit recursion) came from one of my teammates who was at the espresso bar with us, and I used it as a starting point. Like most C programs you might have to stare at it for a while before you figure out how it works :P

No comments

Leave a Reply