For example the problem asks me to:
Write a complete C function named findItem, the prototype of which is given below, that returns the pointer to the first occurrence of an integer value item (specified as a parameter) in an array list. If the value item is not found in the array, the function returns the null pointer. Both the array and its size are specified as parameters.
The solution is:
First of all, why would there be a * in front of findItem?
int * findItem(int * list, int size, int item)
for (i = 0; i < size; i ++)
if (*(list + i) == item)
return list + i;
Secondly, why would some the arguments are passed as pointers while others have not? It seems counterintuive that the whole function is a pointer but the arguments are not.
Lastly, the correct solution given above automatically returns NULL if item has not been found. How is this NULL related to the NULL pointer in the instruction?
Can somebody explain to me how a function prototype that has been declared as a pointer work? Thanks in advance