What is constant?

  • In programming, a constant is a value that never changes. It is a location in computer memory that gets the value before execution of the program and that can be used in the program.
    • Example:  
    • A program to find the circumference of a circle. (Qbasic code)
      INPUT "Enter the radius of circle"; r
      pi = 3.14
      c = 2 * pi * r
      PRINT "The circumference of the circle is "; c

    • In the given program,
      • the value of  'r' is not fixed. Its value can be changed according to the user. So, 'r' is variable.
      • the value of 'pi' is already given so its value is fixed. And it remains same in the entire program. So, 'pi' is constant.
  • A constant may be a character, text or number which can hold any data and which has value assigned before the execution of program.

Share :

Back To Top

facebook main


Powered by Blogger.