What's better?
and why?
Thanks
Asking which is better is not a very good question. They have their place depending on the situation.
I use #defines more than consts, but that is me. I think const can get confusing depending on there you place it.
But one place const can be used where defines can't (and this is where I get almost all of my const usage) is in functions where I do not want the incoming variable to be modified (in a function). Look at the prototype for things liek strcat, printf, etc..
you can use either #define or const in C. But traditionally and the way I still see it taught is:
#define -C const- C++
Mr. C: Author and Instructor
const is more correct in either language imo. defines can be very dangerous. but, they do have their place
hello, internet!
Also, it depend on where you want your thing handled. As I recalle defines are handled in preprocessor, and consts during runtime.
For macros, i always equate them to inline functions in my head and they might cause an executable to be large, depending on how much you use it and such. But that is a bit more complicated, and better off not even used.
Here are several threads with additional thoughts on this matter.