Cpp - Variable Valid Names

Introduction

Names are used to designate variables and functions.

You have to follow the following rules when creating names, which are known as identifiers:

  • a name contains a series of letters, numbers, or underscore characters ( _ ).
  • C++ name is case sensitive.
  • the first character must be a letter or underscore
  • there are no restrictions on the length of a name and all the characters in the name are significant
  • C++ keywords are reserved and cannot be used as names.

Keywords in C++

asm               do                inline             short            typeid 

auto              double            int                signed           typename 

bool              dynamic_cast      long               sizeof           union 

break             else              mutable            static           unsigned 

case              enum              namespace          static_cast      using 

catch             explicit          new                struct           virtual 

char              extern            operator           switch           void 

class             false             private            template         volatile 

const             float             protected          this             wchar_t 

const_cast        for               public             throw            while 

continue          friend            register           true 

default           goto              reinterpret_cast   try 

delete            if                return             typedef 

Examples for names

valid:

a           
US          
us      
VOID 
_var        
Color 
B12         
top_of_window 

a_very_long_name123467890 

invalid:

goto         //reserved word
586_cpu      //cannot start with digit
object-oriented  //cannot have -
US$        //cannot have $
true       //reserved word
 

Related Topic