Now that we’ve had some experiences in programming loops and arrays, let’s talk
ID: 3748706 • Letter: N
Question
Now that we’ve had some experiences in programming loops and arrays, let’s talk about one of the major hazards in the stored program computer that when “going off the end” of a list, an array, or a string can suddenly cause havoc! Do some web research on this issue, and share what you find. Think about strategies you could use to prevent this from happening, or to detect it before you try to add the 26th line of payroll data, into several parallel arrays that are only 25 payroll records deep. If you use additional resources to help in developing your discussion post, be sure to provide proper citation for your source. Generally speaking, your responses should be two to three paragraphs (about 300 to 400 words).
Explanation / Answer
Answer)
In arrays and loops we can go of the ends of a list, an array, or a string and this can cause program errors in the implementation. Thus, this is one of the major hazards in the stored program computer. What we can do to counter this situation in loops and strings and array is that we need to check for the end of the line element after which we will not access or store or update.
Thus, when we have an array of 25 elements, we are using a loop to access the 25 elements. We need to check here that the counter of the loop remains within the 25 elements only, otherwise the array or the loop will be out of bounds of the permitted size in the array or the looping objective to access the elements in the array.
Thus, when we try to access or add the 26 element, it will not at all go to that point, as we will check within the 25 elements only for the counter. Thus by this strategy we can avoid “going off the end” of a list, an array, or a string. For a string also, the length of the string is the key. Thus, when we access the string also, we should be aware of the length of the string using a function and to what extent we can add, update.
Thus, we need to check the upper limit with a counter also here. Thus, the key here is checking the counter of a list, an array, or a string, and thus making sure than no “going off the end” accesses will happen. Thus checking the counter and the length of the concerned data structure will let us know that till what limit the elements are stored and how much can we access or add.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.