Notizen
Variables
Inhalt der Notizen (1)
Seite 1
CONSTANTS
Constants are used in computer programs to store data that does not change. Constants are given self-documenting identifiers that should reflect the data being stored in them. An example of a constant could be Pi - 3.14
VARIABLES
in computer programming a variable may be required to store data that can change, Variables are given identifiers(names) that should reflect the data being stored in the variable
Static variables are stored in a location in memory and have a lifespan that lasts the entire time the program runs
Dynamic variable is assigned a new location in memory and has a lifespan that ends when the sub procedure in which it was defined ends.
A local variable is defined within a sub procedure and is only accessible from within the sub procedure. This is know as its scope
A global variable has a larger scope and is defined globally so is accessible from anywhere within a program.
What is the difference between a variable and a constant
my ans:
A constant is used in computer programs to store data that won't change (is fixed) and a variable is used in computer programs to store data that can change.
textbook ans:
A variable's value can be changed while the programs runs/ A constant's value is fixed it is a set value that cannot be changed while the program runs.
A variable should be radius = int(input())
A constant should be Pi 3.1415
A scope is a the range in which elements of a computer program can act, these elements include variables, constants, function or procedures.
B. Local Variable and Global Variable.