static variables exist for the lifetime of the program static is useful for functions like this:
void func (int i) {
int var = i;
}
when a function is finish executing its code its objects destroys automatically
to prevent this you can use static
void func (int i) {
static int var = i;
}
this mean that when a function finish executing its code the object defined as static will remain until the program ends
const applies for variables, and prevents them from being modified in your code.
and constexpr are used for constant expressions this two is read-only it means that once you initialize a value it cannot be modified
the difference of this two is:
static constexpr int d = 4; // line 4
constexpr int e = a + b + c*d;
in static constexpr int d = 4 is we define a variable named d that is a static constant expression integer and have a value of 4 and cannot be modified and remain until the program ends
and in constexpr int e = a + b + c*d; is we define a variable name e that is
constant expression integer that have a value depends on what the result in those operations and cannot be modified
constorstaticorconstexprmeans.staticmeans.staticmeans the variable exists until the end of the program, but when putstatictogether withconstantorconstexprin global scope,staticdoesn't add additional meaning to the variable when the variable is initialized only withconstorconstexpr.staticmeans in the context of a function body, but you don't know what it means when applied to variables that would otherwise be global.constorconstexprhas default internal linkage, sostaticdoesn't add any meaning to the variable which have been declared byconstorconstexprlike line 3 and 5, so my understanding is that line 3 and 4 have no differences, neither do line 5 and 6.