Constants: Difference between revisions

From Computer Science Wiki
(Created page with "right|frame|Programming basics<ref>http://www.flaticon.com/</ref> In computer programming, a constant is an identifier with an associated value which cann...")
 
No edit summary
Line 1: Line 1:
[[file:arrows.png|right|frame|Programming basics<ref>http://www.flaticon.com/</ref>]]
[[file:arrows.png|right|frame|Programming basics<ref>http://www.flaticon.com/</ref>]]


In computer programming, a constant is an identifier with an associated value which cannot be altered by the program during normal execution – the value is constant<ref>https://en.wikipedia.org/wiki/Constant_(computer_programming)</ref>.  
In computer programming, a constant is an identifier with an associated value which cannot be altered by the program during normal execution – the value of the constant is, well, '''constant'''<ref>https://en.wikipedia.org/wiki/Constant_(computer_programming)</ref>.  


Constants can only be assigned a scalar value, like a string or a number.
A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script. A constant is case-sensitive by default. By convention, constant identifiers are always uppercase.<ref>http://php.net/manual/en/language.constants.php</ref>.
 
== Example ==
 
Below is an example of declaring a constant in PHP:
 
<syntaxhighlight lang="PHP" line>
<?php
 
# this file is used to demonstrate constants in PHP
 
define("SCHOOL_YEAR",    "2016 - 2017");
 
# for the remainder of the running of this program, the value of SCHOOL_YEAR will be 2016 - 2017
 
?>
 
</syntaxhighlight>


== Standards ==  
== Standards ==  

Revision as of 05:01, 20 September 2016

Programming basics[1]

In computer programming, a constant is an identifier with an associated value which cannot be altered by the program during normal execution – the value of the constant is, well, constant[2].

A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script. A constant is case-sensitive by default. By convention, constant identifiers are always uppercase.[3].

Example[edit]

Below is an example of declaring a constant in PHP:

<?php 

# this file is used to demonstrate constants in PHP

define("SCHOOL_YEAR",     "2016 - 2017");

# for the remainder of the running of this program, the value of SCHOOL_YEAR will be 2016 - 2017

?>

Standards[edit]

  • Define the terms: variable, constant, operator, object.

References[edit]