Initialize an integer array of size 10; pass it to a function ‘arrIncrement’ using a void pointer.
The function should increment all elements of the array by one. Then display the
updated array on screen. (use casting)
/*
Initialize an integer array of size 10; pass it to a function ‘arrIncrement’ using a void pointer.
The function should increment all elements of the array by one.
*/
#include <iostream>
void arrIncrement(void * p){
int* a=(int*)p;
for(int i=0;i<10;i++)
(*(a+i))++;
}
int main(void)
{
int a[]={2,5,1,9,7,0,8,-2,55,9};
arrIncrement(a);
for(int i=0;i<10;i++)
std::cout<<*(a+i)<<" ";
std::cout<<std::endl;
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++