WorksheetsVariables: Declaration, Assignment, and Usage
Total questions: 20
Worksheet time: 10mins
Which list shows the correct order of steps when using a variable in ROBOTC?
Use, assign, declare
Assign, declare, use
Declare, assign, use
Declare, use, assign
In the code int speed; which part specifies the variable’s type?
int
speed
;
int speed
Given int speed; speed = 75; startMotor(port3, speed); what does the assignment statement do?
Declares speed as an integer again
Stores the value 75 into speed
Sends speed directly to the motor
Reads a sensor value into speed
Why does changing speed = 75; to speed = 50; affect two startMotor lines without editing them?
Both lines use the variable value
The compiler duplicates assignments
The variable type changes to float
startMotor ignores literal numbers
A student wants both motors to run at the same power but be easy to adjust later. Which approach best meets this goal?
Store the power in one variable
Declare two unused variables
Write the number on both lines
Call startMotor with no variable
Which data type should be used to store the value 35 in ROBOTC?
String data type
Boolean data type
Floating point data type
Integer data type
A sensor reading includes decimal values like 0.56 and 3.0. Which data type best stores these numbers?
Integer without decimals
Floating point with decimals
Boolean true or false
Character single symbol
Which variable name follows ROBOTC naming rules?
time1[T1] with symbols
3distance with leading number
linecounter with no spaces
line counter with a space
You need to indicate whether a condition is met or not in code. Which data type is most appropriate?
Character single letter
Integer whole numbers
String sentence text
Boolean true or false
Which symbol is used to assign a value to a variable in code like x is 5?
The colon colon :: operator
The arrow <- operator
The double equals ==
The equals sign =
A variable already stores 10. After running count = count + 1;, what value is stored in count?
11 after the addition
10 because nothing changes
9 because it subtracts one
20 because it doubles
Given variable1 = 8 and variable2 = 4, what does average = (variable1 + variable2)/2; store in average?
6 after adding then dividing
12 because only sums values
4 because it divides before add
8 because it overwrites nothing
Which statement best describes using a variable on both sides of an assignment, as in sum = sum + x;?
The left side is evaluated first always
The current value is read and updated
The operator copies types automatically
Both sides declare a new variable
Which statement best describes a function in programming?
A hardware component controlling motor power directly
A single variable storing temporary sensor data
A named block of statements run as one unit
A comment explaining steps for future reference
In the code example, why is the keyword "void" used before rotateArm()?
It declares a global constant parameter
It converts wait time into milliseconds
It declares the function.
It forces the motor to stop automatically
Which advantage of functions is shown when rotateArm() is called from task main?
Increasing loop speed by reducing instruction count
Reusing a common behavior without retyping commands
Automatically tuning motor speed using parameters
Replacing all variables with a single constant
In a function definition like void rotateArm(float time), where is the parameter declared?
Inside the parentheses after the function name
Above main in a global constant block
In a separate header outside the code
After the closing brace of the function
A function squareOf(int t) returns t * t. In the call wait(squareOf(100)); what value is used by wait?
No value because return type is void
The value 10000 from squaring 100
The original argument 100 only
A random value assigned at runtime
In a counter-controlled while loop that starts with count = 0 and checks while(count < 4), how many times do the repeated commands run?
Two iterations due to step size
Five iterations including zero and four
Three iterations from 1 through 3
Four iterations from 0 through 3
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?
Motor reverses at half power
Motor toggles on and off rapidly
Motor stops and remains stopped
Motor runs at half power forward
