. Advertisement .
..3..
. Advertisement .
..4..
Here is the program I run:
void getdata(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
int a = srand(time(NULL));
arr[i] = a;
}
}
getdata(arr, 1024);
After I run, it returns an error:
void value not ignored as it ought to be
Does anyone have any suggestions for the problem below: error: void value not ignored as it ought to be c++ in the c – How to correct it?
The cause:
This error happens because
srand
does not return anything, but you are trying to trick it as if it returns a value.Solution:
This error will be fixed if you replace
by
srand(time(NULL))
also need to be placed at the beginning of your program.void srand(unsigned int)
is the prototypesrand
(assuming you include<stdlib.h>
). It returns nothing, but you are using the (???) value it returns. To assigna
by initializationEdit: This is what you should do: