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?
I can think of a good use for define/constant, in microC, Arduino, RoboC and other microprocessor programming languages that are C-based, I/O pins need to be assigned. Since it is easier to refer to the pin by name than number, we use define or constant to assign these pins distinguished names.

Usually, it is preferable to use define because define doesn't take memory like constant, which is quite essential for microprocessors.
#define is evil.

const is type safe. For that reason alone, use define only when you absolutely have to. Const values should not take up a variable, they're usually encoded into the microprocessor program or in other cases embedded at compile time.

Additionally, you need to #define and include in each of your translation units, however with consts you can tell a translation unit that a const is only declared and that it should be linked after the compilation. People used to managed code should find this totally alien.
The major difference with me is that you can write macros with define.
Other than that I use define a lot in cross platform programming to add debug or include special headers.
8 days later
define is preprocessor directives for constants aren't type safe. Where possible prefer const (or static const if appropriate) over defines.

C++ is a very type based language so "int const" is a far better method.

A constant variable will take up space, and finding its value may take more time. A #define will simply be a text replacement of the value 1 in source code. That is, it is directly encoded into the executable.