Variables and Constants Flashcards

1
Q

What is an integer?

A

A positive or negative number with no fractional portion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the range of possible values for an integer?

A

-2 billion to 2 billion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a literal?

A

data that is typed in, hard-coded into a program, and is not calculated from variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a variable?

A

A small piece of the computer’s memory with a name, a specific type of data, and a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can the type of identifier of a variable change?

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the rules for variable names?

A
  • no spaces or special characters
  • cannot start with a number
  • case sensitive
  • can’t be a reservd word
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What characters are allowed to be used in a variable name?

A

letters, digits, and underscores

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is it okay to put variable declarations before the size command?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is it okay to put other commands before the size command?

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens if you use width and height before the size command is called?

A

it will default to 100

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an assignment statement?

A

A statement that changes the value of a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What values are stored in a and b at the end of this program?

a = 10;
b = a;
b = b + 10;

A

a = 10, b = 20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what keyword is used to declare a constant?

A

final

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can you put variables in the size command?

A

No, it must use literals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is scope?

A

The portion of the program where the variable can be used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are global variables?

A

permanent variables whose scope is the entire program after their declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are local variables?

A

variables declared in a block. They are temporary: when the } is reached, they vanish (their scope is their block only).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are state variables?

A

global variables used to keep track of the state of the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Can you have a local and global variable with the same name?

A

Yes. The local variable takes precedence.

20
Q

What are the primitive data types?

A

Number types: int, long, short, byte, float, double
other: boolean, char

21
Q

Why do we need types?

A

The same string of binary means different things depending on what type it is

22
Q

List the integer types in ascending order

A

byte, short, int, long

23
Q

List the floating-point types in ascending order

A

float, double

24
Q

What is the result of 10.0%5

A

Approximately 0.0

25
Q

How would you write ten as an int?

A

10

26
Q

How would you write ten as a long?

A

10L

27
Q

How would you write ten as a float?

A

10.0

28
Q

How would you write ten as a double?

A

10.0D

29
Q

What is the result of 10/3?

A

3

30
Q

What is the result of 10.0/3.0?

A

3.33333333

31
Q

What is the result of 10/3.0?

A

3.33333333

32
Q

What is the result of 10%3?

A

1

33
Q

What is the result of 10.0%3.0?

A

1.0

34
Q

What is the result of
float percent = 33/100; ?

A

0.0

35
Q

If both sides of an operator are numbers, what is the result type?

A

The “biggest” of the two types

36
Q

List the number types in descending order

A

double > float > long > int > short > byte

37
Q

What is the result of 5.0 + 3?

A

the float 8.0

38
Q

What is the result of 5.0D + 3?

A

the double 8.0D

39
Q

What is the result of 5 + 3?

A

the int 8

40
Q

What is the result of 5L + 3.0?

A

The float 8.0

41
Q

Will processing let you divide by zero?

A

no

42
Q

What is the result of 123456*123456?

A

A negative number (overflow)

43
Q

What are the rules for what types of data you can assign to what types of variables?

A

Numbers are automatically converted to “bigger” forms but not “smaller” forms

44
Q

What is casting?

A

Forcing a narrowing conversion

45
Q

How would you cast the float x into an int?

A

(int)x or int(x)