Computer Science ? HW
Computer Science ? HW
HOLIDAY HOMEWORK
WHAT IS A VARIABLE?
• Variable is a name assign to a storage area that the program can manipulate. A variable type
determines the size and layout of the variable’s memory.
• It also determines the range of values which need to be stored inside that memory and nature
of operations that can be applied to that variable
SCOPE OF VARIABLES
• The scope of the variable is simply lifetime of a variable. It is block of code under which a
variable is applicable or alive. For example:
You declare a variable “x” inside a
function “foo.” The scope of that
variable remains inside that function
it can’t be used outside of that
function.
There are three places where
variables you can declare variable
programming language:
• Local Variable is defined as a type of variable declared within programming block or subroutines. It can
only be used inside the subroutine or code block in which it is declared. The local variable exists until the
block of the function is under execution. After that, it will be destroyed automatically.
• A Global Variable in the program is a variable defined outside the subroutine or function. It has
a global scope means it holds its value throughout the lifetime of the program. Hence, it can be
accessed throughout the program by any function defined within the program, unless it is
shadowed.
Example