Hello. I found this program in a book I read the explanation but I don't undersatnd a few things I hope that you guys can help me.
Code:
#include <stdio.h>
#define SIZE 100
int linearSearch(int [], int, int);
int main()
{
int a[SIZE], x, searchkey, element;
for(x=0; x<=SIZE-1; x++)
{
a[x] = 2*x;
}
printf("Enter the integer search key: ");
scanf("%d", &searchkey);
element = linearSearch(a, searchkey, SIZE);
if (element != -1)
{
printf("Found value in element %d\n", element);
}
else
printf("Value not found\n");
return 0;
}
int linearSearch(int array[], int key, int size)
{
int n;
for(n=0; n <=SIZE-1; n++)
{
if (array[n] == key)
return n;
}
return -1;
}
1.
Code:
int linearSearch(int [], int, int);
int linearSearch(int array[], int key, int size)
Why is the function prototype different to the actual function declearation. I thought they were both meant to be the same. And is the program declearing and initilising the variable key, size and the array"array" in the function declearation.
2.
Code:
element = linearSearch(a, searchkey, SIZE);
I totally don't understand this line of code what is it doing and whay is it doing it?