1

I'm getting the error:

lab9q4.c:72:15: warning: passing argument 
1 of 'ReadSalaries' from incompatible 
pointer type [-Wincompatible-pointer-types]
ReadSalaries(&salaries, size);
           ^~~~~~~~~
lab9q4.c:20:26: note: expected 'float **' 
but argument is of type 'float (*) [(sizetype)size]'
void ReadSalaries(float *salaries[], int size)

Here's my code:

float ReadSalary(int num)
{
    int salary;
    printf("Enter Salary %d: ", num);
    scanf(" %d", &salary);
    return(salary);
}

void ReadSalaries(float *salaries[], int size) 
{
    for (int i = 0; i > size; i++)
    {
        *salaries[i] = ReadSalary((i + 1));
    }
}

int main() 
{
    const int size = 10;
    float salaries[size];

    ReadSalaries(&salaries, size);
}
1
  • 1
    It's a good question, but has been answered 100 times. When you take the address of salaries the type is float (*)[size] not float ** (just as your compiler is telling you). C11 Standard - 6.3.2.1 Other Operands - Lvalues, arrays, and function designators(p3) (note the exceptions... particularly the "..the unary & operator.." part.) Also note if you remove the '&' you have a simple float * pointer at your disposal. Commented May 12, 2020 at 3:27

1 Answer 1

2
void ReadSalaries(float *salaries, int size) 
{
    for (int i = 0; i > size; i++)
    {
        salaries[i] = ReadSalary((i + 1));
    }
}

And in the main

ReadSalaries(&salaries[0], size);

You want to change the elements, not the array, so it is safe to pass a simple pointer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.