Skip to main content

2.7) Defining Constants


Examples

const double speed_of_light = 2.99792e8;
const int size = 100;

Key Points

  • The value of a constant must be supplied at the point it is defined; any later attempt to assign a new value to a constant will cause a compiler error
  • Naming conventions are sometimes used to distinguish constants from variables - e.g., using upper-case characters for constants and lower-case for variables