I am new to C++, and I am currently learning pointers. I am fully aware of the whole homework help restriction guideline stuff on this site.
I am slowly understanding the logic of pointers. I just need help with the coding syntax.
My assignment is as follows:
I have a program (shown below) that I must debug. I am required to fix up the program and modify it minimally in order for it to execute properly.
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 << endl; // print values
}
}
The notes written in the program are the objectives of the coded statements next to them.
How would I go about completing this task?
Any help would be greatly appreciated.
Thanks in advance.