Why is it neccessary to use constexpr for MAX_TRIES?

It is possible to just use int MAX_TRIES = 8; so why use constexpr?

1 Like

I have the same doubt. I tried both ways and work the same.

2 Likes

Because we don’t want any part of our code to change MAX_TRIES.
That is the purpose of making a variable ‘const’, to remind ourselves and to make sure that it never changes.

It’s not necessary, but it’s good practice.

2 Likes

Hi @rawstein and dear Community,

just adopt this behaviour as early as much possible. For sure you don’t MUST declare it as a constant but it’s wise, when you know beforhand the variable will never changed, to declare it as a constant.

This course is on a very low level and the course-instructors are high-knowledge personal. Some things will later be clearly to you, trust me.

Kind regards
Kevin

Privacy & Terms