c - 将指针数组传递给函数参数
问题描述
我正在尝试使用相邻链表图数据结构构建总线网络。一个简化的代码如下所示:
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);
}
问题在于addBusRoute(BN->stopsArray, from, to);
似乎我没有传递与函数参数相同类型的值。但是我的理解BN->stopsArray
是指针数组,应该和AdjStopList L[]
. 什么地方出了错?
解决方案
该参数AdjStopList *L[]
与 具有相同的含义AdjStopList **L
。
另一方面,传递BN->stopsArray
的是struct AdjStopList *
.
参数是指向的指针 AdjStopList
,但传递的是指向 的指针AdjStopList
。
因此,类型不同。
推荐阅读
- c - 就字节序而言,是否使用相同的掩码可移植 msb 和 lsb?
- javascript - 为什么我没有收到来自 socket.io 连接事件的任何响应
- c# - 当我将脚本任务与 C# 脚本一起使用时,SSIS 引发错误
- dataframe - 是否可以使用 unix 删除包含特定值的列?
- jquery - window.history.replaceState 在我的 jquery 代码中不起作用
- node.js - 如何解决 UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“0”
- javascript - 使用路由进入 js foreach 循环
- powershell - 如何在 psexec 中使用管道和过滤器?
- c# - Mongodb C#驱动程序向服务器发送消息时发生异常
- python - 无法使用“pool.starmap”将硒驱动程序作为参数传递给函数