What will be printed on the Serial Monitor when this Arduino code runs?
void setup() {
Serial.begin(9600);
printSum(5, 3);
}
void loop() {}
void printSum(int a, int b) {
Serial.println(a + b);
}Remember that Serial.println prints the value passed to it.
The function printSum adds the two numbers and prints the result. 5 + 3 = 8.
What is the main purpose of the setup() function in an Arduino sketch?
Think about what happens when the Arduino first turns on.
The setup() function runs once when the Arduino starts. It is used to initialize settings like pin modes or start serial communication.
What error will this Arduino code cause?
void setup() {
Serial.begin(9600);
greet();
}
void loop() {}
void greet() {
Serial.println("Hello, world!");
}Check punctuation at the end of each statement.
The function greet() is missing a semicolon after the Serial.println statement, causing a syntax error.
What will be printed on the Serial Monitor after running this code?
void setup() {
Serial.begin(9600);
int result = multiply(add(2, 3), 4);
Serial.println(result);
}
void loop() {}
int add(int x, int y) {
return x + y;
}
int multiply(int a, int b) {
return a * b;
}Calculate the inner function first, then the outer.
The add(2, 3) returns 5. Then multiply(5, 4) returns 20, which is printed.
Which option correctly declares a function prototype for a function named blinkLED that takes an int parameter and returns nothing?
Remember the syntax: return_type function_name(parameter_type parameter_name);
Option C correctly declares a function returning void, named blinkLED, with one int parameter named duration.