1

I declared this function :

int dice(int roll[8]) {
blah blah
return (score);

And called it in int main:

newScore = score(roll[8]);

I am getting an invalid conversion from int to int error. What am I doing wrong? The error is on the line where I call it.

3
  • 1) dice has no closing brackets 2) What's score? 3) The "blah blah" section is important because without it, we can't tell you what's wrong with your code. Commented Nov 19, 2013 at 3:19
  • In the call, roll[8] is a single int, not the array. Commented Nov 19, 2013 at 3:19
  • 1
    The error points to the fact that you are expecting an array but passing an integer. What you actually want to pass I can't tell - I personally really don't like declaring a function with a "fixed size array" because you may write code that expects this size, then change your mind when you call it. Better keep these things variable - int dice(int *roll, int n) Commented Nov 19, 2013 at 3:23

1 Answer 1

3
int dice(int roll[8]);

int roll[8];
int newScore = dice(roll);

This is how arrays are "passed" as arguments.

What happens is dice() receives an int* (which may happen to not point to an array of size 8!) and when using roll as an argument, it "decays" into a pointer to its first element.

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.