简体   繁体   中英

Pass an array of pointers to function argument

I am trying to construct a bus network using adjacent linked list graph data structure. A simplified code is shown below:

typedef struct BusNetwork
{
    struct AdjStopList *stopsArray;  //defing the array of pointers
} BusNetwork;

typedef struct Node
{
    int stopID;
    struct Node *next;
} Node;

typedef struct AdjStopList
{
    char stopName[20];
    int numOfAdjStp;
    struct Node *first;
} AdjStopList;

void insertStopAtLast(AdjStopList *L, int stopID)
{
    //add stopID to the last node of the list
    return;
}

void addBusRoute(AdjStopList *L[], int from, int to)
{
    if (from == to)
        return;

    insertStopAtLast(L[from], to);
    return;
}

void main(BusNetwork *BN, int from, int to)
{
    addBusRoute(BN->stopsArray, from, to);
}

The problem is with addBusRoute(BN->stopsArray, from, to); It seems I didn't pass the same type of value as function argument. But my understanding of BN->stopsArray is an array of pointers, which should be the same as AdjStopList L[] . What went wrong?

The argument AdjStopList *L[] has the same meaning as AdjStopList **L .

On the other hand, what is passed BN->stopsArray is struct AdjStopList * .

The argument is a pointer to a pointer to AdjStopList , but what is passed is a pointer to AdjStopList .

Therefore, the type differs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM