Having an issue displaying the contents of the loaded array using a pointer. Below i've posted my code. This is a homework assignment so i'd rather not get the answer but more so an explanation. When i run the program, it prints all 2's.
run the code and select menu item #1. input 1,2,3,4,5 for testing. then select menu item #2 and it will output 2's for all addresses
Hi, your code seems alright. The only thing that needs changing is line 102 where you are always adding by 1. Instead of that, try adding by index x.
1 2 3 4
for (int x = 0; x < SIZE; x++)
{
cout << "\nProperty #" << ++count << ": " << *(pointer + x);
}
EDIT: Sorry, did not explain. In the first iteration. every time you go *(pointer + 1), the pointer points to the 2nd element of the array since you are advancing it by just 1. Then the next iteration, the pointer will also point to the 2nd element because the pointer by default will always point to the first element of the array and you are only adding one to it, so it is still [0] + [1]. So you want a way to say pointer + 1, then pointer + 2, then pointer + 3, .... n - 1. Hope that made sense.