Question: Beginner's C++ code: #include #include using namespace std; int main() { int data[5]; int counter = 1; while (counter < 5){ data[counter] = counter *

Beginner's C++ code:

#include #include using namespace std; int main() { int data[5]; int counter = 1; while (counter < 5){ data[counter] = counter * 10; counter = counter + 1; } cout << data[1] << "-" << data[4] << endl; return 0; } 

a) Why is the output to this code 10-40, when arrays are zero offset? Does setting the counter = 1 and then setting data[counter] negate the original zero offset that arrays have?

b) does this mean data[0] would return an error?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!