Trying to initialize array but i get an error no matter what i do. what am i doing wrong?
1 2 3 4 5 6 7 8 9 10 11
void bD (int n, int r, int b[])
{
b[] = {1,0,0,1}; //this yields an error of "expected expression"
}
or
void bD (int n, int r, int b[6])
{
b[6] = {1,0,0,1}; //this yields an error of " excess elements in scalar initializer"
}
What exactly are you trying to accomplish? Why are you trying to pass an array by value in your parameters. If you want to modify the array you should be passing it by reference. Also, you can only pass the address of the array, not the whole block of memory itself if that makes sense.
Check out this link, scroll down to "arrays as parameters"
Actually he's passing the array correctly.
But it's not possible to do that operation when it's already constructed. You have to set each value one by one.