C++ – Validity of Single Underscore as Variable Name

c++standardsvariable-names

With gcc 4.7.2 this compiles just fine for me:

int main()
{
  int _ = 1;
  return 0;
}

Can I expect this to compile in general? I've read the answers about underscores as prefixes. But what if the underscore isn't prefixing anything?

Best Answer

Yes, from The C++ Programming Language, 4th Edition:

A name (identifier) consists of a sequence of letters and digits. The first character must be a letter. The underscore character, _, is considered a letter.