Answer to Question #73482 in C++ for mian

Question #73482
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)
1
Expert's answer
2018-02-14T05:53:11-0500
/*
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS