In C++, how to manipulate the elements in an array with pointers

All About Code
2 min readMay 19, 2022

Question

Update the array values from { 5, 10, 15 } to { 30, 20, 10 } using pointers. In the end of the method, print out the elements in the array using pointers as well.

Solution

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

--

--