Question
In problems that ask you to change code, make the few changes necessary to fix the code without changing its overall approach. For example, don't
In problems that ask you to change code, make the few changes necessary to fix the code without changing its overall approach. For example, don't fix the program in problem 1a by changing it to int main() { cout << " 30 20 10" << endl; } 1. The subparts to this problem involve errors in the use of pointers. a. This program is supposed to write 30 20 10, but it doesn't. Find all of the bugs and show a fixed version of the program: int main() { int arr[3] = { 5, 10, 15 }; int* ptr = arr; *ptr = 10; // set arr[0] to 10 *ptr + 1 = 20; // set arr[1] to 20 ptr += 2; ptr[0] = 30; // set arr[2] to 30 while (ptr >= arr) { ptr--; cout << ' ' << *ptr; // print values } cout << endl; }
Step 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