Symbolic Constants in C

Symbolic Constants in C – Symbolic Constant is a name that substitutes for a sequence of characters or a numeric constant, a character constant or a string constant.

When program is compiled each occurrence of a symbolic constant is replaced by its corresponding character sequence.

The syntax of Symbolic Constants in C

#define name text
where name implies symbolic name in caps.
text implies value or the text.

For example,

#define printf print
#define MAX 50
#define TRUE 1
#define FALSE 0
#define SIZE 15

The # character is used for preprocessor commands.

A preprocessor is a system program, which comes into action prior to Compiler, and it replaces the replacement text by the actual text.

This will allow correct use of the statement printf.

Advantages of using Symbolic Constants

They can be used to assign names to values.

Replacement of value has to be done at one place and wherever the name appears in the text it gets the value by execution of the preprocessor.

This saves time. if the Symbolic Constant appears 20 times in the program; it needs to be changed at one place only.


One thought on “Symbolic Constants in C

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: