What are the rules about using an underscore in a C++ identifier?


From MSDN docs −

Use of two sequential underscore characters ( __ ) at the beginning of an identifier, or a single leading underscore followed by a capital letter, is reserved for C++ implementations in all scopes. You should avoid using one leading underscore followed by a lowercase letter for names with file scope because of possible conflicts with current or future reserved identifiers.

So you should avoid using names like −

__foo, __FOO, _FOO

And names like the following should not be used in the global namespace −

_foo, _bar

Other than this, there are some more prefixes like LC_, SIG_, and suffixes like _t should not be used as they're also reserved for the implementation.

So you can create variables that contain the underscore between the name or ends with an underscore.


Updated on: 11-Feb-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements