The define part of the c/c++ language is able to save on coding time. The define is only really good for a one line of code that a function would be far to much of a over kill.
Here are three examples of the define,
#define MAXVALUE 20 |
this will allow for a hard coded value to be used within the coding
#define PrintHello cout << "Hello" << endl; |
this will print hello when you call the marco as
void main() { PrintHello; } |
and last is passing parameters to the marco
#define PrintWord(word) cout << word << endl; |
will change the word parameter within the code to the passed value for example both will work
void main() { PrintWord("hi there"); PrintWord(3); } |
since the marco will convert the passed parameter to the value.