S
Simon Morgan
Can somebody please explain why the following piece of code generates an
error unless I change q[top--] to *q[top--]:
typedef int Queue[10];
int top = 9;
void insert(Queue *q, int n) {
q[top--] = n;
}
$ gcc -c test.c
test.c: In function `insert':
test.c:5: error: incompatible types in assignment
Seeing as q is essentially a pointer to an array I assumed that I could
use array notation but I'm obviously mistaken so I'd just like to know why
it doesn't work.
Thanks.
error unless I change q[top--] to *q[top--]:
typedef int Queue[10];
int top = 9;
void insert(Queue *q, int n) {
q[top--] = n;
}
$ gcc -c test.c
test.c: In function `insert':
test.c:5: error: incompatible types in assignment
Seeing as q is essentially a pointer to an array I assumed that I could
use array notation but I'm obviously mistaken so I'd just like to know why
it doesn't work.
Thanks.