In C/C++, what is the difference between using #define
[and #ifndef
#endif
] to create values, when you can easily do it with an int
or std::string
[C++] too?
#ifndef MYVAL
#define MYVAL(500)
#endif
//C++
cout << MYVAL << endl;
//C
printf(MYVAL);
//C++
int MYVAL = 500;
cout << MYVAL << endl;
//C
int MYVAL = 500;
printf(MYVAL);
Your assumptions are wrong. #define
doesn't create "values", it creates replacement text in your source code. It has basically nothing to do with C or C++ at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With