0

I want to initialise my a variable with queue type. But im running into a bit of trouble. The warning says incompatible pointer to integer conversion assigning to int. What does this mean?

#include <stdio.h>
#include <stdlib.h>
#define MAX 4

struct queue
{
    int array[MAX];
    int front;
    int back;
};
typedef struct queue Queue;

Queue qInit(Queue table[], int front, int back);

int main(void)
{

    Queue table[MAX];
    int front, back;

    qInit(table, front, back);

    return 0;
}

Queue qInit(Queue table[], int front, int back)
{
    Queue c;

    c.array[MAX]=table;  // <---- getting warning right here.
    c.front=front;
    c.back=back;

    return c;
}
3
  • if array is in size MAX, there is no element in the index of MAX, it's only ranging from 0 to MAX-1. Aside of that, as table is an array of integers, you can't implicitly assign a pointer (table is an array, therefore a pointer) to an integer spot Commented Oct 29, 2016 at 19:31
  • @ZachP not quite sure what you mean... Commented Oct 29, 2016 at 20:27
  • 1
    Alex it is not clear what you are trying to do. The line with the warning is because array is for integers, but you are trying to put a Queue in to it. c.array[X] can only be given an integer, and X would have to be from 0 to MAX-1, because MAX is 4, the valid index to the array are 0,1,2 and 3, not 4. Commented Oct 29, 2016 at 23:11

1 Answer 1

1

the problem is (what @Zach P is also trying to explain) array[MAX] contains MAX number of values with index 0 to MAX-1 and there is no position MAX so last index is array[MAX-1].

and secondly table is a pointer to an array so you cant assign a pointer to a int variable (array[MAX-1] is of type int)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.