WorksheetsPIF Session 5B Assessment
Total questions: 20
Worksheet time: 7mins
Name
Class
Date
1.
What is the purpose of the switch...case statement in Arduino?
a)
To repeat a block of code multiple times
b)
To define a function
c)
To select one of many code blocks to be executed based on a variable's value
d)
To pause program execution for a specific time
e)
To declare an array
2.
What does the following code snippet do? <br> while (count < 10) {<br> // Code to be executed<br> count++;<br> }
a)
Executes the code block 9 times
b)
Executes the code block 10 times
c)
Executes the code block 11 times
d)
Executes the code block indefinitely
e)
Causes a compile-time error
3.
What is the purpose of the break; statement in a switch...case structure?
a)
To skip to the next case
b)
To exit the entire program
c)
To exit the switch...case structure
d)
To pause program execution
e)
To define a new variable
4.
What is the purpose of the continue; statement in a loop?
a)
To exit the loop completely
b)
To skip the rest of the current iteration and proceed to the next
c)
To pause loop execution
d)
To define a new variable
e)
To restart the loop from the beginning
5.
What is the correct way to declare an array of 5 integers named myArray in Arduino?
a)
int[5] myArray;
b)
myArray int[5];
c)
int myArray{5};
d)
int myArray[5];
e)
array myArray[5];
6.
What does the following code snippet do? <br> for (int i = 0; i < 5; i++) {<br> myArray[i] = i * 2;<br> }
a)
Fills the array with random numbers
b)
Fills the array with the numbers 0 to 4
c)
Fills the array with the numbers 0, 2, 4, 6, 8
d)
Fills the array with the numbers 2, 4, 6, 8, 10
e)
Causes a compile-time error
7.
What is the index of the last element in an array of size 10?
a)
10
b)
9
c)
1
d)
It depends on the data type of the array
8.
What is the purpose of a function in Arduino programming?
a)
To store data
b)
To define a constant
c)
To group a block of code for reusability
d)
To control program flow
e)
To declare variables
9.
What does the return statement do in a function?
a)
Indicates the start of the function
b)
Defines the parameters of the function
c)
Ends the function and optionally returns a value to the caller
d)
Declares a local variable within the function
e)
Prints a value to the Serial Monitor
10.
What is the purpose of the void keyword in a function definition?
a)
To indicate that the function does not take any arguments
b)
To indicate that the function does not return any value
c)
To define a global variable
d)
To declare a constant
e)
To include a library
11.
What is the difference between a local variable and a global variable in Arduino?
a)
A local variable can only be used within the loop() function, while a global variable can be used anywhere
b)
A local variable is declared inside a function, while a global variable is declared outside any function
c)
A local variable is an integer, while a global variable is a floating-point number
d)
A local variable is a constant, while a global variable can be changed
e)
There is no difference
12.
What is the purpose of the preprocessor directive #define in Arduino?
a)
To include a library
b)
To declare a variable
c)
To define a constant
d)
To start the program execution
e)
To write data to a digital pin
13.
What is the purpose of the const keyword in Arduino?
a)
To include a library
b)
To declare a variable
c)
To define a constant
d)
To start the program execution
e)
To write data to a digital pin
14.
What is the difference between = and == in Arduino programming?
a)
= is used for addition, while == is used for equality comparison
b)
= is used for assigning a value to a variable, while == is used for comparing two values
c)
= is used for comparing two values, while == is used for assigning a value to a variable
d)
= is used for declaring a variable, while == is used for defining a constant
e)
There is no difference
15.
What is the purpose of a semicolon (;) in Arduino programming?
a)
To indicate the start of a code block
b)
To indicate the end of a code block
c)
To mark the end of a statement
d)
To define a comment
e)
To include a library
16.
What is the output of the following code snippet? <br> int a = 5;<br> int b = 10;<br> int c = a + b;<br> Serial.println(c);
a)
5
b)
10
c)
15
d)
510
e)
Error
17.
What is the output of the following code snippet? <br> int x = 10;<br> int y = 3;<br> int z = x % y;<br> Serial.println(z);
a)
3
b)
1
c)
10
d)
30
e)
Error
18.
What is the output of the following code snippet? <br> float a = 5.0;<br> float b = 2.0;<br> float c = a / b;<br> Serial.println(c);
a)
2
b)
2.5
c)
5
d)
10
e)
Error
19.
What does the following code snippet do? <br> if (temperature > 30) {<br> digitalWrite(fanPin, HIGH);<br> }
a)
Turns the fan on if the temperature is less than 30 degrees
b)
Turns the fan off if the temperature is greater than 30 degrees
c)
Turns the fan on if the temperature is greater than 30 degrees
d)
Turns the fan off if the temperature is less than 30 degrees
e)
Does nothing
20.
What does the following code snippet do? <br> if (buttonState == HIGH) {<br> digitalWrite(ledPin, HIGH);<br> } else {<br> digitalWrite(ledPin, LOW);<br> }
a)
Turns the LED on if the button is not pressed
b)
Turns the LED off if the button is pressed
c)
Turns the LED on if the button is pressed and off if it is not pressed
d)
Turns the LED off if the button is pressed and on if it is not pressed
e)
Does nothing
100 %
