what is use of macro in c language ?
macro
Collapse
X
-
Suppose your program needed a "maximum allowed value" of 10. You could hard-code 10's all over your code and tings would wrok fine. Then if you needed to change the maximum value to 25 you could edit all of your code and manually change he 10 to 25.
Or you could use a macro:
Now you hard-code MAXVALUE instead of 10. Then when you need to change the 10 to 25, you just change the #define and rebuild your code.Code:#define MAXVALUE 10
You can also use a #define to represent code. Plenty of examples for this on the web.
Comment