Variables and Assignments Flashcards

(20 cards)

1
Q

Variable Declaration

What is a variable declaration?

A

A variable declaration is a statement that declares a new variable, specifying the variable’s name and type.

For example, int userAge; declares a new variable named userAge that can hold an integer value.

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

Variable

What is a variable in programming?

A

A variable is a named item used to hold a value, such as x or numPeople.

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

Memory Allocation

What does memory allocation mean in the context of variables?

A

Memory allocation is the process of determining a suitable memory location to store data like variables. Each variable has a memory address that stores its value.

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

Assignment Statement

What is an assignment statement?

A

An assignment statement assigns a value to a
variable.

Example: x = 5; assigns the value 5 to x. The variable retains this value until it is assigned again.

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

Assignment with Expressions

What can the right side of an assignment statement contain?

A

The right side of an assignment can be an expression, such as a number (5), a variable (x), or a calculation (x + 2).

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

Assignment with Same Variable on Both Sides

What happens when a variable appears on both sides of an assignment statement? Give an example.

A

The variable on the left is updated using the value on the right.

Example: If x = 6, then x = x + 1; updates x to 7. The original value is overwritten.

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

Incrementing a Variable

What does it mean to increment a variable?

A

Incrementing a variable means increasing its value by 1.

Example: x = x + 1; increments x.

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

Expression

What is an expression in programming?

A

An expression is a combination of values, variables, and operators that evaluates to a single value.

Examples: 80, numApples, x + 2.

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

Integer Literal

What is an integer literal?

A

An integer literal is a whole number directly written in code, such as 80.
Note: Commas are not allowed in an integer literal, so 1,333,555 is written as 1333555.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly