Passing a pointer to an array in a structure

What is wrong with my front function? I want to pass a pointer to a specific line in my array in order to read / edit it.

struct queue { char itens[LN][CL]; int front,rear; }; char *front(struct queue * pq) { return pq->itens[pq->front+1][0]; } 
+4
source share
2 answers

You are currently returning a single char , not a pointer to a string. Remove [0] :

 char *front(struct queue *pq) { return pq->itens[pq->front+1]; } 
+7
source

You get access to char and do not use its address. Using:

 &(pq->itens[pq->front+1][0]) 

Please note that external parsers are optional.

+5
source

Source: https://habr.com/ru/post/1486130/


All Articles