Why are constants used instead of variables? -


in general occasions constants used instead of variables. need few examples.

thanks in advance.

variable names, varies on time. variables allocate memory. compiler when value wont change, can series of optimizations (no space allocated constants on stack) , benefit of constants.

update

you may ask why use constants after all?

it's question, can use literal numbers instead of constants. doesnt make difference compiler. sees both same. more readable code (programming practice), desired use constants.

by using constants can save time! suppose rate value products in shopping system (rate value = 8.14). system works constant several months. after months wanna change rate value. do? have 1 awful option! changing literals numbers equal 8.14 ! when declare rate constant (in programming language) have change constant value once , then, changes promote.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -