+ 1
What is the use of constant class?
Why would we want to use constant objects? Could someone give me some examples where it might be useful? Edit: I understand the use of constant variables to hold constant values such as pi, but what about constant class?
3 Antworten
+ 2
Pi? Days of week? Months of year? etc... Anything that is constant and doesn't change - opposite of a variable.
+ 1
A way to make code easier is the most common.
However, declaration of constants can be based on preprocessor directives. You may want to restrict a buffer size based on the platform, for example.
0
It also saves a lot of memory as your program will know that this variable cannot be changed later on in the code.