c - 那个条件是什么意思?
问题描述
在 if 条件下应该current -> yes
评估什么?(这不是完整的代码,您可以假设任何问题是的)
typedef struct node {
char *question;
struct node *no;
struct node *yes;
} node;
node *current;
if (current->yes) {
current = current->yes;
}
非常感谢您的帮助
解决方案
通过取消引用 对象,您将获得yes
type 成员的地址。也就是说,如果正确分配内存,它将是非零,如果不是,它将是 0 或. 例如,内存分配可能会失败。struct node *
current
NULL
所以,基本上条件:if (current->yes) { ... }
检查内存是否分配正确。
推荐阅读
- python - 如何导出 csv 或文本文件中的所有链接?
- c# - 将项目转换为 NETSDK 格式后表单中的资源异常
- python-3.x - 多台计算机通信 - multiprocessing.Listener,确保端口保持可用?
- spring - 在 @SpringBootTest 中自动装配时,WebTestClient 为空
- roslyn - Roslyn - 获取对分配给属性的字符串的引用
- network-interface - Azure 网络接口有效规则
- docx4j - 邮件与 docx4j 合并后,docx 仍然是一个模板文件
- esp32 - PlatformIO 图标未显示在我的 VStudio IDE 中
- ubuntu - 安装 sg3-utils 并使用它连接 Apple Superdrive 后,Ubuntu 上的音频失真
- php - PHP 会话在服务器的某些站点中不起作用