Sie sind auf Seite 1von 1

A symbolic constant is a name that is used in place of a sequence of characters.

The character may represent numeric constant , a character consists of a short s tring constant. When a program is compiled , each occurrence of a symbolic cons tant is replaced by it s corresponding character sequence. these constants are def ined at the beginner of the program. The syntax for defining a symbolic constant is: #define name value Examples: #define pi 3.1428 #define size 70 Rules for defining a symbolic constant: symbolic constant have the same form as variable name. Generally , these are def ined in capital letter to visually distinguish them from the normal variable, bu t it is only convention. A blank space is required between #define and symbolic name and between symbolic name and it s value. No blank space between the # and word define is permitted. After definition, the symbolic name should not be assigned any other value withi n the program by using an assignment statement. Advantages of using symbolic constants: 1. Modifiable: Generally , when a constant is being used at more than one statement in C, symbo lic constant is sued in place of actual constant . the advantage of this is: If we have to change value of the constant used in different places ; we can modify it s value simply by changing value of symbolic constant at one place. if symboli c constant is not used , we would have to search through the program and explici tly change the value of constant whenever it is being used. If any value is left unchanged , the program may produce incorrect output. 2. Understandability: When , a numeric vague appears in a program , it s use is not always clear special ly when the same value represents different values in different places. For exam ple the number 10 may mean the number of students at one place and the size of a rray at another place of the same program. Assignment of symbolic name instead o f actual numeric value in such case removes such problem. For example : We may u se the name no_of_students to define the number of students and size of array.

Das könnte Ihnen auch gefallen