Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

int array[10] - { 6, 4, 10, 3, 9, 15, 2, 4, 11, 13 }; void setup() { Serial.begin(9600); int k = 3; int i

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions