Motivation: the
information need of computer programs
- A computer program
processes
information (data)
-
Information (data)
used in
computer programs
can be broadly categorized
in the following
2 categories:
-
Long term
information that are
used by
multiple
functions/methods
Example:
- The
StackTop for
a stack
data structure is
used by
push( ) and
pop( )
|
-
Short term
information that are
used by
one
function/method
Example:
- A
loop index i in
a for-loop
inside a function/method
for ( int i = 0; i < 10; i++ ) ....
|
|
|
|
Concepts to
support the
information need of computer programs
- Programming languages
provide
different
kinds
of variables
to accommodate
the information need of
computer programs
- Java:
|
Review concept:
life time and
scope
of variables
- Variables in
a high level programming language
always
have the following
2 properties:
- The
life time of a
variable the
the
(time)
period between:
- When the
variable
created (=
allocated)
(i.e.:
begins
to exist)
- When is a
variable
destroyed (=
de-allocated)
(i.e.:
ends to
exist)
|
- The
scope of a
variable:
- Scope =
the
portion
of the
computer program where
a variable can
be
accessed (=
used
in expressions)
|
- Note:
- You should have learned about the
life time and
scope of the
4 kinds of
variables of
Java in
CS170 and CS171
|
|
❮
❯