Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Variables: Declaration, Assignment, and Usage

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which list shows the correct order of steps when using a variable in ROBOTC?

a)

Use, assign, declare

b)

Assign, declare, use

c)

Declare, assign, use

d)

Declare, use, assign

2.

In the code int speed; which part specifies the variable’s type?

a)

int

b)

speed

c)

;

d)

int speed

3.

Given int speed; speed = 75; startMotor(port3, speed); what does the assignment statement do?

a)

Declares speed as an integer again

b)

Stores the value 75 into speed

c)

Sends speed directly to the motor

d)

Reads a sensor value into speed

4.

Why does changing speed = 75; to speed = 50; affect two startMotor lines without editing them?

a)

Both lines use the variable value

b)

The compiler duplicates assignments

c)

The variable type changes to float

d)

startMotor ignores literal numbers

5.

A student wants both motors to run at the same power but be easy to adjust later. Which approach best meets this goal?

a)

Store the power in one variable

b)

Declare two unused variables

c)

Write the number on both lines

d)

Call startMotor with no variable

6.

Which data type should be used to store the value 35 in ROBOTC?

a)

String data type

b)

Boolean data type

c)

Floating point data type

d)

Integer data type

7.

A sensor reading includes decimal values like 0.56 and 3.0. Which data type best stores these numbers?

a)

Integer without decimals

b)

Floating point with decimals

c)

Boolean true or false

d)

Character single symbol

8.

Which variable name follows ROBOTC naming rules?

a)

time1[T1] with symbols

b)

3distance with leading number

c)

linecounter with no spaces

d)

line counter with a space

9.

You need to indicate whether a condition is met or not in code. Which data type is most appropriate?

a)

Character single letter

b)

Integer whole numbers

c)

String sentence text

d)

Boolean true or false

10.

Which symbol is used to assign a value to a variable in code like x is 5?

a)

The colon colon :: operator

b)

The arrow <- operator

c)

The double equals ==

d)

The equals sign =

11.

A variable already stores 10. After running count = count + 1;, what value is stored in count?

a)

11 after the addition

b)

10 because nothing changes

c)

9 because it subtracts one

d)

20 because it doubles

12.

Given variable1 = 8 and variable2 = 4, what does average = (variable1 + variable2)/2; store in average?

a)

6 after adding then dividing

b)

12 because only sums values

c)

4 because it divides before add

d)

8 because it overwrites nothing

13.

Which statement best describes using a variable on both sides of an assignment, as in sum = sum + x;?

a)

The left side is evaluated first always

b)

The current value is read and updated

c)

The operator copies types automatically

d)

Both sides declare a new variable

14.

Which statement best describes a function in programming?

a)

A hardware component controlling motor power directly

b)

A single variable storing temporary sensor data

c)

A named block of statements run as one unit

d)

A comment explaining steps for future reference

15.

In the code example, why is the keyword "void" used before rotateArm()?

a)

It declares a global constant parameter

b)

It converts wait time into milliseconds

c)

It declares the function.

d)

It forces the motor to stop automatically

16.

Which advantage of functions is shown when rotateArm() is called from task main?

a)

Increasing loop speed by reducing instruction count

b)

Reusing a common behavior without retyping commands

c)

Automatically tuning motor speed using parameters

d)

Replacing all variables with a single constant

17.

In a function definition like void rotateArm(float time), where is the parameter declared?

a)

Inside the parentheses after the function name

b)

Above main in a global constant block

c)

In a separate header outside the code

d)

After the closing brace of the function

18.

A function squareOf(int t) returns t * t. In the call wait(squareOf(100)); what value is used by wait?

a)

No value because return type is void

b)

The value 10000 from squaring 100

c)

The original argument 100 only

d)

A random value assigned at runtime

19.

In a counter-controlled while loop that starts with count = 0 and checks while(count < 4), how many times do the repeated commands run?

a)

Two iterations due to step size

b)

Five iterations including zero and four

c)

Three iterations from 1 through 3

d)

Four iterations from 0 through 3

20.

A robot uses a bumper switch and this code:
if(SensorValue(bumper)==0)
{
startMotor(port3,63);
}
else {stopMotor(port3);}
What happens when the bumper is pressed?

a)

Motor reverses at half power

b)

Motor toggles on and off rapidly

c)

Motor stops and remains stopped

d)

Motor runs at half power forward