static there are variables for the lifetime of a static program useful for such functions:
void func (int i) { int var = i; }
when a function finishes executing its code, its objects are automatically destroyed to prevent this, you can use static
void func (int i) { static int var = i; }
this means that when the function finishes executing its code, the object defined as static will remain until the program finishes
const is applied to variables and does not allow them to change your code. and constexpr are used for constant expressions, these two are read-only, this means that after initialization the values ββcannot be changed
the difference of these two:
static constexpr int d = 4;
in static constexpr int d = 4 we define a variable called d, which is a constant of an integer constant expression and has a value of 4 and cannot be changed and remains until the program finishes
and in constexpr int e = a + b + c*d; we define the name of the variable e, which constant expression integer, which has a value, depends on the result in these operations and cannot be changed
Kryssel tillada
source share