If there is a constant appearing in several places in your program, it's a good idea to associate a symbolic name to the constant, and then use the symbolic name to replace the constant throughout the program. There are two advantages to doing so. First, your program will be more readable. Second, it's easier to maintain your program. For instance, if the value of the constant needs to be changed, find the statement that associates the constant with the symbolic name and replace the constant with the new one. Without using the symbolic name, you have to look everywhere in your program to replace the constant. Sounds great, but can we do this in C?
Well, C has a special program called the C preprocessor that allows you to define and associate symbolic names with constants. In fact, the C preprocessor uses the terminology macro names and macro body to refer to the symbolic names and the constants. The C preprocessor runs before the compiler. During preprocessing, the operation to replace a macro name with its associated macro body is called macro substitution or macro expansion.
You can put a macro definition anywhere in your program. However, a macro name has to be defined before it can be used in your program.
In addition, the C preprocessor gives you the ability to include other source files. For instance, we've been using the preprocessor directive #include to include C header files, such as stdio.h, stdlib.h, and string.h, in the programs throughout this book. Also, the C preprocessor enables you to compile different sections of your program under specified conditions.
What Is the C Preprocessor?
Related Items
C প্রোগ্রামিং এর Scope এবং Storage Classes এর বর্ণনা
CLASS 14 - Scope and Storage Classes in C
Strings কে সঠিক ভাবে ফরম্যাট করা ও ব্যবহার করা
CLASS 13 - Manipulating Strings
অনুরূপ অনেক Data একসাথে স্টোর করতে array এর ব্যবহার
Storing Similar Data Items
Pointers এর ব্যবহার ও তার প্রয়োজনীতা
Chapter 11 - An Introduction to Pointers
প্রোগ্রাম Controls করার পদ্ধতি ও তার সঠিক ব্যবহার
Chapter 10 - Getting Controls