Search code examples
variablesconstants

What are the real-world uses of Constants in Programming?


I understand that declaring constants is a way to use same identifiers whose value isn't going to change over time. But I just couldn't think of real life use-cases where it is extensively used. Also when do we really need to use a constant instead of a variable in any programming language?


Solution

  • By defining a constant, you won't need to put the same values hardcoded in your code periodically. You can avoid repetition. And you can modify these group values at once by modifying their definition.