Question: int array[10] - { 6, 4, 10, 3, 9, 15, 2, 4, 11, 13 }; void setup() { Serial.begin(9600); int k = 3; int i
int array[10] - { 6, 4, 10, 3, 9, 15, 2, 4, 11, 13 }; void setup() { Serial.begin(9600); int k = 3; int i = 0; bool itemFound = false; 7/interate through the array to find the location of k while ( itemFound = false) { if ( array[i]-- ) { itemFound = true; //stop the loop i++; //increment i by 1 Serial.println(i); Part a: The above code is meant to print the location of k within the array. What is printed to the serial monitor? Is this correct? Explain. Write your answer here Part b: How could you redesign this code to be "defensive"? In other words, how could you make sure all cases are covered so that, if k is not found, the code does not access the array past it's size. Put your revised code here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
