Is it possible to increment the array passed to a function?
I have a single dimensional array a[4] = {10,20,30,40}, I want to call a function and increment the array to point to 3rd element and print it from main().
For ex:
int main()
{
int a[4] = {10,20,30,40};
cout << *a; // 10
increment(); // function call
cout << *a; // 40
}
How can we accomplish this?If array is passed as a pointer, only the modification to the value stored in array get reflected. What is the prototype of the function if we have to increment the array in function?
Alternative to as suggested is:
Use a second pointer to access the original array and modify that in the function…
Further alternative is to use either
std::vector<int>,std::array<int, 4>and then pass an iterator to the function (and get it to return an iterator)…