C++ Constants

Constants are named data-storage locations.  C++ has two types of constants: literal and symbolic. 
Literal constant is simply a value typed into the code. In following example 40 and Cat are the known as a literal constants.
E.g.
nCounter = 40;
strAnimalName = "Cat";

Symbolic constant is represented by a name.Its defined exactly the same way as a variable but the qualifier must start with the keyword const and the variable must be initialized.
E.g.
const int nMaxIterations = 49;
const unsigned long nMaxCharInFile = 123234;


Advantages of using Symbolic Constants:

  • The symbolic names make the program more readable.
  • It’s easier to change a single symbolic constant value than to find and replace all occurrences of a literal in a code.

No comments:

Post a Comment

Golang: Http POST Request with JSON Body example

Go standard library comes with "net/http" package which has excellent support for HTTP Client and Server.   In order to post JSON ...