|
|
|
C++
Names/Variables
C++ Names
When using the various necessary variables in your programs,
you will need to identify each one of them. A variable is
primarily recognized by its name. C++ provides rules for
naming items in your program.
The name of a variable:
-Starts with an underscore “_” or a letter, lowercase or
uppercase, such as a letter from a to z or from A to Z.
-Examples are Name, gender, _Students, pRice
-Can include letters, underscore, or digits. Examples are:
keyboard, Master, Junction, Player1, total_grade, _Score_Side1
-Cannot include special characters such as !, %, ], or $
-Cannot include an empty space
-Cannot be any of the reserved words
-Should not be longer than 32 characters (although allowed)
-A name can consist of one word such as country. A name could
also be a combination of more than one word, such as firstname
or dateofbirth.
The C++ compiler has a list of words reserved for its own use
and you must not use any of these words to name your own
objects or functions. The reserved words are:
C and C++ Reserved Words
auto
break
case
char
const
continue
default do
double
else
enum
extern
float
for goto
if
int
long
register
return
short signed
sizeof
static
struct
switch
typedef union
unsigned
void
volatile
while
Some of these words are used by KDevelop or could come in
conflict with various libraries. Therefore, avoid using these
additional words:
C++ Reserved Words
asm
bool
catch
class
cin
const_cast
cout
delete dynamic_cast
explicit
false
friend
inline
interrupt
mutable
namespace new
operator
private
protected
public
register reinterpret_cast static_cast
string
template
this
throw
true
try typeid
typename
union
using
virtual
wchar_t
Avoid starting the name of a variable with two underscores;
sometimes (most of the time), the compiler would think that
you are trying to use one of the words reserved for the
compiler.
C++ is case-sensitive; this means that CASE, Case, case, and
Case are four completely different words. To make your
programming experience easier and personal, you can add your
own rules to those above. Some (most) companies also adopt a
naming convention throughout their documentation.
-kolij-
|
|