| | |
C++ Identifiers and Keywords
![]() |
•
•
Join Date: Feb 2003
Posts: 129
Reputation:
Solved Threads: 1
In C++ we provide names for the entities we create, the variables, functions and types in our programs. These names, or identifiers, are required to conform to some simple rules.
Valid Characters
An identifier must start with a letter and is comprised of a sequence of letters and digits. Somewhat surprisingly, in this context the underscore _ is considered to be a letter (although there are conditions associated with its use). There's no restriction on the length of an identifier.
Use of Underscore
Identifiers beginning with an underscore followed by an upper case letter are reserved for use by the implentation, as are identifiers beginning with a two consecutive underscores, so to avoid problems you should refrain from using them for your own identifiers.
Keywords
You can't use an identifier that is a C++ keyword in your programs. Keywords are:
and, and_eq, asm, auto, bitand, bitor, bool, break, case, catch, char, class, compl, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, not, not_eq, operator, or, or_eq, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while, xor, xor_eq.You should also try to avoid using names from the C++ library, e.g. swap, max.
Case Sensitivity
C++ is case sensitive, so upper case and lower case characters are distinct. This means that the names userInput and userinput are recognised as two different identifiers.
Examples
Examples of acceptable identifiers are:
calculate_height, readWindSpeed, channel42, foo, BARExamples of unacceptable identifiers:
calculate height, delete, 2letters, _HELLO_Hints and Tips
Use meaningful descriptive names to make your code more easily understood,
e.g.
int height rather than int h,Avoid names that differ only in capitalisation
char menuSelection rather then char ch,
int patient_age rather than int number.
e.g. height, Height.
Avoid using names that are keywords but with different capitalisation
e.g. Return, Continue.
Try to maintain a consistent style
Examples are:
- Capitalising all words except the first,
e.g. readInUserData(), getMaximumSpeed().
- Using underscore to separate words,
e.g. read_in_user_data(), get_maximum_speed().
- Using a type identifier prefix,
e.g. int nGetSomeIntegerValue, char szDataString[].
•
•
Join Date: Jun 2005
Posts: 28
Reputation:
Solved Threads: 0
This tutorial is very helpful for beginning programmers because it provides a summary of keywords.
Also it is nice to have a simple referance on the rules for vriable names.
-----------------
Programming ( Assignment / Project ) Help
Also it is nice to have a simple referance on the rules for vriable names.
-----------------
Programming ( Assignment / Project ) Help
•
•
Join Date: Jul 2005
Posts: 10
Reputation:
Solved Threads: 0
This is one good intro to programming using C ++, and just to add please get an emphasis of using the surfixes ie
int Age_integer // age declared as an integer
or
char Name_character[10] // name as an array of 10 characters
becasue it makes it easier when doing the coding as you dont have to go back to the beggining to find out the type of your identifiers
int Age_integer // age declared as an integer
or
char Name_character[10] // name as an array of 10 characters
becasue it makes it easier when doing the coding as you dont have to go back to the beggining to find out the type of your identifiers
![]() |
Similar Threads
- Lexical Analyzer (C++)
- Using keywords in forum titles (Search Engine Optimization)
Other Threads in the C++ Forum
- Previous Thread: problem with tic-tac-toe! help.
- Next Thread: move() function ?
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes code coding compaitibility compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error factorial file floatingpoint forms fstream function functions game givemetehcodez graph guessing gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix maze memory multiple net news node oop output parameter payment pointer problem program programming project projectassignmenthelp protection python random rank read recursion reference rpg skills string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets





