1

The program should find the maximum value of the array, but I'm facing an error I cannot fix.

I get the following error:

invalid conversion from 'int*' to 'int'.

Replacing int by float works as expected.

#include<stdio.h>
void find_biggest(int, int, int *);
int main()
{
    int a[100], n, *biggest;
    int i;
    
    printf("Number of elements in array ");
    scanf("%d",&n);
    
    for(i=0;i<n;i++)
    {
        printf("\nEnter the values: ");
        scanf("%d",&a[i]);
    }
    
    find_biggest(a, n, &biggest); //invalid conversion  from 'int*' to 'int'
    
    printf("Biggest = %d",biggest);
    
    return 0;
}

void find_biggest(int a[], int n, int *biggest)
{
    int i;
    *biggest=a[0];
    for(i=1; i<n; i++)
    {
        if(a[i]>*biggest)
        {
            *biggest=a[i];
        }
    }
} 

2 Answers 2

1

You've got a mismatch between your function prototype:

void find_biggest(int, int, int *);

And definition:

void find_biggest(int a[], int n, int *biggest)

Since you're passing the array a as the first argument, the definition is correct and the prototype is incorrect. Change it to:

void find_biggest(int [], int, int *);

Or:

void find_biggest(int *, int, int *);

You're also passing the wrong type for the third argument. You define biggest as an int pointer and are passing its address, so the given parameter has type int ** when it expects int. So change type type of biggest to int.

int a[100], n, biggest;
Sign up to request clarification or add additional context in comments.

Comments

0

The word find is a word reserved in langage C,you must avoid it

#include<stdio.h>
int main()
{
   int a[100], n, *biggest;
   int i;

printf("Number of elements in array ");
scanf("%d",&n);

for(i=0;i<n;i++)
{
    printf("\nEnter the values: ");
    scanf("%d",&a[i]);
}

biggest_array(a, n, &biggest); //invalid conversion  from 'int*' to 'int'

printf("Biggest = %d",biggest);

return 0;
}

void biggest_array(int a[], int n, int *biggest)
{
int i;
*biggest=a[0];
for(i=1; i<n; i++)
{
    if(a[i]>*biggest)
    {
        *biggest=a[i];
    }
}
}

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.