MCS-011 Problem Solving and Programming

First year, Semester 1

Chapters

Newsletter

Symbolic Constants

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 is as follows:

#define name text

[where name implies symbolic name in caps.
text implies value or the text. ] 

For example,
#define printf print
#define MAX 100
#define TRUE 1
#define FALSE 0
#define SIZE 10  

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 are:

  1. They can be used to assign names to values
  2. 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 
      

Report an issue

Reporting: Symbolic Constants (topic)

Related Posts