Home   |   About   |   Terms   |   Contact    
Read & Learn
 

What is Symbolic Constant in C++?

C++

☯ All C++ Articles     ☯ All Articles


A new product.




Popular Google Pages:



◕ This article is regarding
What is Symbolic Constant in C++?
Common practice to use Symbolic Constant.
What is Qualifier in C++?

Last updated on: .




◕ What is Symbolic Constant in C++?

- Let we have a statement to declare a variable like this:
const int Months = 12;

Here Months is a symbolic constant for 12.
Now we can use this symbolic constant Months in a program instead of the number 12.

A number 12 in a program might represent the number of inches in a foot or the number of pencils in a dozen.
But the name months in that program will tell us what the value 12 represents.
It makes a programmer's job easy.

If the program uses the constant months in several places and we need to change the value of it, then we can just change the statement to change all the values of months.
It saves our time and tensions.



◕ Convention way to declare a Symbolic Constant

- There is no universal convention way to declare a Symbolic Constant.
But there are some common practices to declare the Symbolic Constant so that it can remind us that it is a constant.
As a result we can separate constants from the variables in a program.

▨ Capitalize the first character.
Example:
const int Months = 12; // Months is symbolic constant for 12

▨ Make all the characters uppercase.
const int MONTHS = 12; // MONTHS is symbolic constant for 12

▨ Begin constant names with the letter k.
Example:
const int kmonths = 12; // kmonths is symbolic constant for 12





◕ What is Qualifier in C++?

- Consider the statement to declare the variable:
const int Months = 12;

In the above statement the keyword const is termed as Qualifier.
Because it qualifies the meaning of a declaration.



Related articles:
List of Symbolic Constant in C++
What is char16_t and char32_t in C++?
Integer Type in C++
Rules for Variable Names
Variable in C++
Fundamental Data Types & Compound Data Types
What is called Directive and Header File in C++ ?
What is Block Statement in C++ ?


Popular Google Pages:



Top of the page

Amazon & Flipkart Special Products

   


Top of the page