Question
In the code snippet below, the array arr is declared in line #7 with a size of 4 with 4 initial values also defined. However,
In the code snippet below, the array
arr
is declared in line #7 with a size of 4
with 4 initial values also defined.
However, in line #9 to #11, the arrays are accessed to be printed. The loop is
set at SIZE+2 in line #9 which means that we will access values beyond that of
the array. C++ does not check for out-of-bound access in an array.
Output printed from the loop in #9 to #11 is shown below.
Last two values are invalid because they are values beyond the array.
You will now define an array that will check for the array bounds.
Design an array called
myArray
according to this declaration.
Here is definition of empty constructor in line #13
Here is definition of constructor in line #11 specifying the upper bound of the
array
4 const int SIZE=4; 6 int main() int arr[SIZE] {3,14, 7,81); = 8 9, 10 for(int 1-0;1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started