Learning C, I'm trying to implement a little program. I have two structs like this:
typedef struct QueueNode_ QueueNode;
typedef struct TQueue_ TQueue;
struct QueueNode_ {
QueueNode* next;
const Task task;
};
struct TQueue_ {
QueueNode* first;
QueueNode* last;
};
Next I defined a method to initialize my queue:
void initializeQueue(TQueue* queue){
queue = malloc(sizeof(TQueue)); //check if malloc returns NULL!
queue->first = NULL;
printf("%d", queue->first == NULL);
queue->last = NULL;
}
And the main:
int main() {
puts("TQueue example:");
TQueue q;
initializeQueue(&q);
printf("%d", q.first == NULL);
}
I though that the above would print 11 but it prints 10 meaning that my pointer first is not set to null. I'm pretty sure that I miss something basic...
Why the above prints 10 and how to initialize properly the pointer of first to NULL in my initializeQueue method?
Thanks!