Why not create a global constant instead of using so much syntax for one statement?

I’m wondering if there is a benefit in using:

constexpr data_type variable = bound_value; (within the scope of a function such as main() )

over just creating a global constant outside of any function such as:

int WORD_LENGTH = 8;

int main(){

std::cout << WORD_LENGTH << std::endl;

return 0;
}

What is this opposed to?

For this current lecture I suppose this makes sense but further down we want to get this value from the HiddenWord so we can change the word without having to go about changing that constant as well.
Also getting people into making global variables this early on could lead to bad coding practices pretty quickly as most of the time global’s are not the right approach.

I meant:

Instead of typing: constexpr data_type variable = bound_value; (within the scope of a function)
Why not just use a global constant instead?

Well it’s better than poluting the global scope.

1 Like

Privacy & Terms