首页 > 解决方案 > 那个条件是什么意思?

问题描述

在 if 条件下应该current -> yes评估什么?(这不是完整的代码,您可以假设任何问题是的)

typedef struct node {
    char *question;
    struct node *no;
    struct node *yes;
} node;

node *current;

if (current->yes) {
    current = current->yes;
}

非常感谢您的帮助

标签: c

解决方案


通过取消引用 对象,您将获得yestype 成员的地址。也就是说,如果正确分配内存,它将是非零,如果不是,它将是 0 或. 例如,内存分配可能会失败。struct node *currentNULL

所以,基本上条件:if (current->yes) { ... }检查内存是否分配正确。


推荐阅读