Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: indirection requires pointer operand

Tags:

c

pointers

I have the following functions, an initializeHeap function which takes in no arguments and outputs a Heap struct which I have defined. And an insertNode function which takes in a pointer to a heap struct and the number to be added to the heap. I call them in the main function as such:

h = initializeHeap();
Heap *p = *h;
insertNode(p,5);
insertNode(p,7);
insertNode(p,3);
insertNode(p,2);

I get this error when trying to do this:

error: indirection requires pointer operand

Any ideas? I can post more code if needed.

The struct Heap and function initializeHeap() are as follows:

typedef struct node{
    int data;
}Node;

typedef struct heap{
    int size;
    Node *dataArray;
}Heap;

Heap initializeHeap(){
    Heap heap;
    heap.size = 0;
    return heap;
}
like image 572
jsmith102894 Avatar asked Mar 29 '15 15:03

jsmith102894


1 Answers

Change:

Heap *p = *h;

to

Heap *p = &h;

h is a Heap structure object, use & operator to get a pointer to the structure object.

like image 126
ouah Avatar answered Oct 23 '22 18:10

ouah