Quick overview of const and define.
const is a keyword used to indicate to the compiler that your variable should not be altered throughout your program. If you do try to alter it, compiler will return an error (some compiler will only return a warning!).
define is a simple text replacement operation, where every occurrence of your keywords will be replaced by the pre-processor before compilation. It has the clear advantage of not declaring a variable and therefore not taking up memory.
So here are my questions:
- Can you mention a case where the use of const or define is necessary?
- Practically, which use is preferred?
const is a keyword used to indicate to the compiler that your variable should not be altered throughout your program. If you do try to alter it, compiler will return an error (some compiler will only return a warning!).
define is a simple text replacement operation, where every occurrence of your keywords will be replaced by the pre-processor before compilation. It has the clear advantage of not declaring a variable and therefore not taking up memory.
So here are my questions:
- Can you mention a case where the use of const or define is necessary?
- Practically, which use is preferred?