Skip to main content

Command Palette

Search for a command to run...

Symbolic Constants

Published
1 min readView as Markdown

A symbolic constant is a name given to any constant. In C, the preprocessor directive

#define

is used for defining symbolic constants. #define instructions are usually placed at the beginning of the program. By convention, the names of symbolic constants are written in uppercase, but this is not compulsory. The syntax for creating a symbolic constant is as follows:

#define constant_name value

For example:

#define PI 3.14

It will define a symbolic constant

PI

having value 3.14. When we use PI in our program, it will be replaced with 3.14 by the compiler automatically.

The rules below apply to a

#define

statement that defines a symbolic constant.

  • No blank space is allowed between the # symbol and the word define.

  • The character in the line should be #.

  • A blank space is required between the constant name and #define and between the constant name and the value.

  • A semicolon must not be used at the end of a #define statement.

  • Within the program, the symbolic constant should not be assigned any other value.

Example

#include <stdio.h>
#define PI 3.1415

int main(){
float radius=10, area;
area = PI*radius*radius;
printf("Area=%.2f",area);
return 0;
}
3 views

More from this blog

P

Programming Tutorials

89 posts