How Symbolic Constant Defined In C Language?
Hello Programmer,
Today we will discuss What is symbolic constant in c language? How is a symbolic constant defined in c language? Rules and advantage of a symbolic constant declaration?
Definition:
A symbolic constant is a quantity or value which never changed during program compilation.
It is a name that is used in place of any numeric constant, a character constant or a string.
whenever the program is compiled, each occurrence of a symbolic constant is replaced by its corresponding character constant.
In C programming language symbolic constant is defined before the main function with the help of hash sign(#).
Syntax: #define name value
In syntax, as you see I use to 'name', it has the same form as variable names and one thing to remember is whenever you declare symbolic constant no blank space is used between the hash sign(#) or the word define.
Example: #define PI 3.1428
#define length 30
Now we will discuss some rule which is necessary to declare a symbolic constant.
The rule for defining a symbolic constant in c language:
1) Whenever you declare symbolic constant you must ensure that a blank space is required between #define and symbolic name and it's value.
2) Symbolic constant has the same name as a variable name but the symbolic constant name defines in capital letter to visually distinguish them from the normal variable.
3) Blank space is prohibited between the # sign and word define.
4) When you define symbolic name you should not be assigned any other value through the program by using an assignment statement.
5) The symbolic constant must start with a '#' sign.
6) You can not use a semicolon after the #define statement.
7) You can use #define statement in whole program but first, it is referenced in the program.
Now we will discuss some advantage of symbolic constant in c language.
Advantages of symbolic constant in c language:
1) Symbolic constant reduces the chances of error in the program. It reduces the chance of typing the wrong value error.
2) Symbolic constant avoided the repetition of value. There is no need to repeat the value of the same constant in every expression.
3) Symbolic constant reduces the effort of writing the same value in a different place in the program.
4) It increases understandability. When the same value represents different values in different places in a program, it causes confusion.
5) Symbolic constant enhances the readability of the program.
Share Is Caring...
Comments :
Post a Comment