Font size
WorksheetsVariables in RobotC
Total questions: 15
Worksheet time: 10mins
Which of the following are rules for Variable Names?
A variable name can not have spaces in it
A variable name can have symbols in it
A variable name can not start with a number
A variable name can not be the same as an existing reserved word
Which of the following are proper Variable Names?
line counter
distance3
timecounter
time1[T1]
Which data type has positive and negative whole numbers, as well as zero?
String
integer
Boolean
Floating Point Decimal
Which data type has a string of characters that can include numbers, letters, or typed symbols?
integer
string
boolean
floating point decimal
Which data type uses True or False and is useful for expressing the outcomes of comparisons?
floating point decimal
integer
string
boolean
Which are three main steps involved in using a variable?
Introduce (create or “declare”) the variable
Give (“assign”) the variable a value
Use the variable to access the stored value
Introduce (create or “declare”) the variable
Use the variable to access the stored value
Give (“assign”) the variable a value
Give (“assign”) the variable a value
Introduce (create or “declare”) the variable
Use the variable to access the stored value
True or False? In the declaration the variable is created by announcing its type, followed by its name.
True
False
True or False? During the assignment the variable is assigned a value and a name
True
False
Which of the following are rules for the assignment of variables?
Values are assigned using the assignment operator = (not ==
Math operators (+, -, *, /) can be used with assignment statements to perform calculations on the values before storing them
A variable can not appear in both the left and right hand sides of an assignment statement; this simply means that its current value will not be used in calculating the new value
Assignment can be done in the same line that a variable is declared (e.g. int x = 0; will both create the variable x and put an initial value of 0 in it)
True or False? You can use a variable simply by putting its name where you want its value to be used
True
False
True or False? The current value of the variable will be used every time the variable appears
True
False
Which one is the correct description of the following statement?
sum = variable1 + variable2;
Adds the value in “variable1” to the value in “variable2”
stores the result in the variable “sum”
Adds the value in “variable1” to the value in “variable2”, and stores the result in the variable “sum”
Adds the sum of variable 2 and 2 as the increment
Which is the correct description for the following statement?
count = count + 1;
Adds 1 to the current value of “count” and places the result back into “count” (effectively, increases the value in “count” by 1)
Adds 1 to the current value of “count” and places the result back into “count” (effectively, increases the value in “count” by 2)
Adds the current value of “count” to 1 and places the result plus one back into “count” (effectively, increases the value in “count” by 2)
Which one is the most correct description of the following statement?
int zero = 0;
Add zero as the integer
(combination declaration and assignment statement)
Creates the variable x with an initial value of 0 (combination declaration and assignment statement)
Declare zero as an integer
Declare zero as an initial integer
True or False?
With a robot, however, the ability to store sensor values (values that are measured by the robot, rather than set by the programmer) adds invaluable new capabilities. It gives the robot the ability to take measurements in one place and deliver them in another, or even do its own calculations using stored values.
True
False
