Print service provided by iDogiCat: http://www.idogicat.com/
home logo





Home > IT > Programming > C++ Programming > Hungarian Notation

Hungarian Notation

Charles Simonyi is credited with first discussing Hungarian Notation. It is a variable naming convention that includes C++ information about the variable in its name (such as data type, whether it is a reference variable or a constant variable, etc). Every company and programmer seems to have their own flavor of Hungarian Notation. The following is just what we thought seemed easy for beginning students to understand.

PrefixTypeExample
bbooleanbool bStillGoing;
ccharacterchar cLetterGrade;
strC++ Stringstring strFirstName;
sishort integershort siChairs;
iintegerint iCars;
lilong integerlong liStars;
ffloating pointfloat fPercent;
ddouble-precision floating pointdouble dMiles;
ldlong double-precision floating pointlong double ldLightYears;
szOld-Style Null Terminated Stringchar szName[NAME_LEN];
ifInput File Streamifstream ifNameFile;
isInput Streamvoid fct(istream &risIn);
ofOutput File Streamofstream ofNameFile;
osOutput Streamvoid fct(ostream &rosIn);
Sdeclaring a structstruct SPoint {};
Cdeclaring a classclass CPerson {};
struct name or abbrevdeclaring an instance of a structSPoint pointLeft;
SPoint ptLeft; // or abbrev. (be consistent)
class name or abbrevdeclaring an instance of a classCPerson personFound;
CPerson perFound; // or abbrev. (be consistent)

The following table contains letters that go before the above prefixes.

Pre-prefixTypeExample
uunsignedunsigned short usiStudents;
kconstant formal parametervoid fct(const long kliGalaxies)
rreference formal parametervoid fct(long &rliGalaxies)
sstaticstatic char scChoice;
rgarray (stands for range)float rgfTemp[MAX_TEMP];
m_member variable of a struct or classchar m_cLetterGrade;
ppointer to a single thingchar *pcGrade;
prgdynamically allocated arraychar *prgcGrades;