First, I agree with the above reply that we rarely need to use void pointer as an argument.
However, I still think there are some circumstances that we need it.
Anyway, for this case, why don't you change it to
-
void func(int* v, int n, int val) {
-
or
-
void func(int v[], int n, int val) {
-
instead, so that you don't have to worry about changing the type.
Another alternative way would be to use "memset" function.
You can find a documentation
here
And if you want to use this function for many types of data, I suggest you define it using "
template " like this:
-
template <class T>
-
void func(T* v, T n, T val) {
-
T* xp = v;
-
for(T* i=xp; i<xp+n; i++)
-
*i = val;
-
}
-
*I think you want to put "val" there instead of "5", so I changed it.