The 404-not-found Code of StackOverFlow


The famous programmers’ Q&A site shows the following image that contains a piece of code when some content is not available.

stackoverflow-404-code The 404-not-found Code of StackOverFlow brainfuck c / c++ programming languages

stackoverflow-404-code

So, what is this?

1
2
3
4
5
# define v putchar
#   define print(x) main(){v(4+v(v(52)-4));return 0;}/*
#>+++++++4+[>++++++<-]>++++.----.++++.*/
print(202*2);exit();
#define/*>.@*/exit()
# define v putchar
#   define print(x) main(){v(4+v(v(52)-4));return 0;}/*
#>+++++++4+[>++++++<-]>++++.----.++++.*/
print(202*2);exit();
#define/*>.@*/exit()

First, the above is a valid C/C++ code, if you remove comments /* .. */ and the C code will look like this:

1
2
3
4
# define v putchar
#   define print(x) main(){v(4+v(v(52)-4));return 0;}
print(202*2);exit();
#define/*>.@*/exit()
# define v putchar
#   define print(x) main(){v(4+v(v(52)-4));return 0;}
print(202*2);exit();
#define/*>.@*/exit()

And this can be further expanded to:

1
2
3
4
main() {
  putchar(4 + putchar(putchar(52) - 4));
  return 0;
}
main() {
  putchar(4 + putchar(putchar(52) - 4));
  return 0;
}

The putchar function gets executed in this order:

  • putchar(52): 52 is the ascii code for number ‘4’
  • putchar(52) returns 52 so putchar(putchar(52)-4) is the same as putchar(48) which prints out 0
  • putchar(4 + 0) which prints the 4 again

However, if you compile using gcc command gcc -o a.out stackoverflow.c you will get a few warnings but that still gives you the compiled binary that prints 404.

The second program hidden is the Perl, which treats the line starting with # as comments, so the above C code will be interpreted in Perl as:

1
print(202*2);exit();
print(202*2);exit();

And if you run perl stackoverflow.c the 404 will be printed to console.

Finally, there is also a BrainFuck code hidden. The Brainfuck interpreter will ignore invalid characters (treat them as comments), so the above will be equivalent to:

>+++++++4+[>++++++<-]>++++.----.++++.

Using this online BrainFuck interpreter, it outputs 404.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
393 words
Last Post: How to Implement the "some" Function in C++ using Templates?
Next Post: How to Hide Feature Image of Posts in WordPress?

The Permanent URL is: The 404-not-found Code of StackOverFlow

One Response

  1. Rafael

Leave a Reply