Write about Symbolic Constants (or) #define statement

The constants which will be used in number of places in a program can be defined using # define statement.

Ex:    #define PI 3.14
         #define STRENGTH  100

Syntax: #define symbolic_name value_of_constant

Rules for defining symbolic constants:

1.Symbolic names have the same form as var names (symbolic names are written in CAPITALS to visually distinguish them in lowercase letter. This is only a convention, not a rute).

2. No blank space between the powd sing ‘#’ and the word define is permitted.

3. ‘#’ must be the first character in the line.

4. A blank space is required between #define & symbolic name & between the symbolic name and the constant.

5. #define statement must not end with a semicolon.

6. After definition, the symbolic name should not be assigned any other value within the program by using an assignment statement.

7. Symbolic names are NOT declared for datatypes. Its datatype depends on the type of constant.

8. #define statements may appear anywhere in the program but before it is referenced in the program.

9.#defube statement is a preprocessor compiler directive.

Example:

1) Write a Program to find area of  a circle

            #include< stdio.h>
            #define PI 3.14
            void main( )
            {
               float area, r;
               scanf(“ enter r value”);
              area = PI * r * r;
              printf(“ Area of a circle is % F”, area);
            }

Related

C Language 2776544818067237020

Post a Comment

emo-but-icon

item