What is this smiley-with-beard expression: "<:]{%>"?

Xeo picture Xeo · Apr 1, 2013 · Viewed 12.8k times · Source

I came across the following program, which compiles without errors or even warnings:

int main(){
  <:]{%>; // smile!
}

Live example.

What does the program do, and what is that smiley-expression?

Answer

0x499602D2 picture 0x499602D2 · Apr 1, 2013

The program uses digraphs to represent the following:

[] {};

This is a lambda expression that does nothing. The corresponding symbols have these equivalents:

<: = [
%> = }

Though they are generally unneeded today, digraphs are useful for when your keyboard lacks certain keys necessary to use C++'s basic source character set, namely the graphical ones. The combination of the characters that make up a digraph are processed as a single token. This in turn makes up for any insufficiently-equipped keyboards or other such hardware or software.