Variables and Constants Flashcards
What is an integer?
A positive or negative number with no fractional portion
What is the range of possible values for an integer?
-2 billion to 2 billion
What is a literal?
data that is typed in, hard-coded into a program, and is not calculated from variables
What is a variable?
A small piece of the computer’s memory with a name, a specific type of data, and a value
Can the type of identifier of a variable change?
no
What are the rules for variable names?
- no spaces or special characters
- cannot start with a number
- case sensitive
- can’t be a reservd word
What characters are allowed to be used in a variable name?
letters, digits, and underscores
Is it okay to put variable declarations before the size command?
yes
Is it okay to put other commands before the size command?
no
What happens if you use width and height before the size command is called?
it will default to 100
What is an assignment statement?
A statement that changes the value of a variable
What values are stored in a and b at the end of this program?
a = 10;
b = a;
b = b + 10;
a = 10, b = 20
what keyword is used to declare a constant?
final
Can you put variables in the size command?
No, it must use literals
What is scope?
The portion of the program where the variable can be used
What are global variables?
permanent variables whose scope is the entire program after their declaration
What are local variables?
variables declared in a block. They are temporary: when the } is reached, they vanish (their scope is their block only).
What are state variables?
global variables used to keep track of the state of the program