#define MY_INT VS const int MY_INT

c++, c-preprocessor, constants

Solution

#define WEEKDAYS 7

void f() {
    int WEEKDAYS = 3; // error
}

const int WEEKDAYS_CONST = 7;

void g() {
    int WEEKDAYS_CONST = 3; // okay: local scope for WEEKDAYS_CONST
}

Problem

Possible Duplicate: “static const” vs “#define” in c When I do this : ``` #define WEEKDAYS 7 ``` and that : ``` const int WEEKDAYS = 7; ``` Any difference between them ? seems that both do the same thing - sets a constant value for future usage within the code .

Original source

Related problems