Anonymous

Why Do People Use "#"define In Turbo C?

1

1 Answers

Misbah Arshad Profile
Misbah Arshad answered
Perhaps you wonder what we have gained by substituting PI for 3.14159 in our program. Hopefully we have made program easier to read. Although such a common constant as 3.14159 is easily recognized, there are many instances where a constant does not reveal its purpose so readily. For example, as we will find out later, the phrase "\x1B[C" causes the cursor to move one space to the right. But which would you find easier to understand in the middle of your program, "\x1B[C", or "CURSOR_RIGHT"? Thus, we would use #define directive:

#define CURSOR_RIGHT "\x1B[C"

Then whenever CURSOR_RIGHT appeared in the program, it would automatically be replaced by "\x1B[C" before compilation began.

There is another, perhaps more important reason for using the #define directive in this way. Suppose a constant like 3.14159 appears many times in your program. Further suppose that you now decide you want an extra place of precision. you need to change all instances of 3.14159 to 3.141592. Ordinarily, you would need to go through the program and manually change each occurance of the constant. However, if you have defined 3.14159 to be PI in a #define directive, you only need to make one change, in the #define directive itself:

#define PI 3.141592

The change will be made automatically to all occurances of PI before compilation begins.

Answer Question

Anonymous