Monday

Constants in C++

About constants :-
                                As everyone of us knows that a constant is something whose value can not be changed and in C++ program it works as it works in mathematics because in mathematics the constant have just one still value. In C++ program a constant can not be used like a variable because it does not have storage. There are different types of C++ constants (mostly of four types) and they are given below:

                      
  1. Integer. 
  2. Character.
  3. String.
  4. Boolean.
It is also very important to know that how a constant is given a name? The answer is as follows :
Assigning names to constants :-
                                                  Basically a constant is assigned a name by keeping an eye on all those rules on which we keep during assigning names to variables but an only thing which should be addicted that is the constants are preferred to be written in capital letters.

       

       Methods of assigning names :-

                                              There are specially two types of assigning names to the constants :
  • By using #define keyword or operator .
  • By using const keyword .

Both of the methods have been explained below with proper syntax.
1) By using #define keyword :-
                                              In this method constant is assigned name outside the main function's boundary. Equal's sign and terminator are not used. And the proper syntax is given below :

                                                    

2) By using const keyword :-
                                              In this type the name of the constant is assigned inside the main function's boundary. In it equal's sign and terminators are also used. The syntax is given below :

                                         



To find source code : http://pastebin.com/NFVeEAAA

No comments:

Post a Comment