So I wanted to write a function to reverse a linked list using an array of pointers but I'm getting warnings: assignment from incompatible pointer type [-Wincompatible-pointer-types]. I wanted to store the pointers to nodes of the list in an array of pointers int **s = (int **)calloc(10, sizeof(int)); and thought that s[*top] = *l will assign the pointer to which **l is pointing to *topth element of array *s[]. So am I wrong thinking that elements of array *s[] are pointers? If someone could explain it to me I'd be very glad. Here's the whole code (except the part where I create the list which is fine):
typedef struct list {
int v;
struct list *next;
} list;
void reverseListS(list **l, int **s, int *top) {
while ((*l)->next != NULL) {
s[*top] = *l;
*top++;
*l = (*l)->next;
}
list *temp = *l;
while (!(*top == 0)) {
temp->next = s[*top];
*top--;
temp = temp->next;
}
temp->next = NULL;
}
int main() {
int **s = (int **)calloc(10, sizeof(int));
int *top = 0;
reverseListS(&l, s, top);
}
main: Should besizeof(int *)(orsizeof *s). Although, I think you wantsto be an array of ints, so it should be anint *. Andtopdoes not point anywhere - why is it even a pointer?.lis not initialized....list *l, I can edit it. I thought that there is not difference betweensizeof(int *)andsizeof(int)since amount of bytes used to store an integer is the same as a pointer to integer (correct me if im wrong). I madetopa pointer so that changing its value inside the function will affect it outside too. ifswould be an array of ints could I assign a pointer to a value stored in that array? because I tried to do that and it didnt work and googled that you can't realy point a pointer to an address stored in an integer variable.