What is the difference between constants and read-only variables that are used in programs?

Constants perform the same tasks as read-only variables with some differences. The differences between constants and read-only are
Constants:

  1. Constants are dealt with at compile-time.
  2. Constants supports value-type variables.
  3. Constants should be used when it is very unlikely that the value will ever change.

Read-only:

  1. Read-only variables are evaluated at runtime.
  2. Read-only variables can hold reference type variables.
  3. Read-only variables should be used when run-time calculation is required.
Tagged . Bookmark the permalink.

Leave a Reply