Hello, I have got a question, in the following code:
When passing the array into the function the array values don't change. However, if I just put the function contents directly in main(), I manage to change the values of the array.
Am I doing something wrong?
Code:
void func(void* v, int n, int val) {
int* xp = reinterpret_cast<int*>(&v);
for(int* i=xp; i<xp+n; i++)
*i = 5;
}
int main() {
int array[10];
func(array, 10, 5);
for (int j=0; j<10; j++)
cout << array[j] << endl;
}
Am I doing something wrong?
Comment