I'm a C beginner (come from a Java and Ruby background) and I'm trying to learn C by completing some tutorials.
One tutorial gives some sample code to complete and I'm struggling with one line in particular. The code contains a sort function with the following prototype:
Code:
void sort (int *data[], int n, comp_ptr compare, swap_ptr swap);
which is called in main.c like so:
Code:
sort((int**) employees, no_employees, comp_employee, swap_employee);
The thing that's confusing me is the first parameter. employees is defined like so:
Code:
Employee *employees[10];
with Employee being defined as:
Code:
typedef struct emp_struct
{ char name[100];
int employee_no;
float salary, tax_to_date;
} Employee;
It seems that employees, in the above function call, would represent a pointer to to the first element in its array (which would itself represent a pointer to an Employee). What I don't understand -- really at all -- is how the (int**) cast would convert employees into a pointer to the first element of a array of pointers to ints, as specified in the sort function prototype.
It seems like this is meant to convert an array of pointers to ints to an array of pointers to Employees. Is that actually what's happening? What happens when a program points to something expecting an int but actually gets an Employee?
Any assistance here would be much appreciated. Many thanks!