Symbolic Constants

It is a bad practice to use ‘magic numbers’ or sequence of characters in a program, as it is difficult for a new person to understand the significance of the magic number in the program. Magic numbers are constants like 249,10 etc. The best way to replace those is a symbolic name or symbolic constant. A #define line defines it

#define name replacement list

The further use of the name will be replaced by the replacement text. Thereafter, in place of the magic number we can use the replacement text. The replacement list is not limited to numbers.

#define X sorry

Symbolic constants are conventionally written in upper case so that it could be distinguished from lower case variable names.Another important thing is there is no semi-colon at the end of #define line.

Advertisements

About Odol Shinu

I've completed my B Tech in Information Technology in 2010 from Government Engineering College Sreekrishnapuram Palakkad under Calicut University.

Posted on August 6, 2010, in C Language. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: