gpt4 book ai didi

连续 if 语句流程

转载 作者:行者123 更新时间:2023-11-30 21:03:38 28 4
gpt4 key购买 nike

if (srcbloc == NULL) {
fprintf(stderr, "warning!: memrip source is null!\n");
exit(1);
}
if (destbloc == NULL) {
destbloc = malloc(len);
}
if (srcbloc == destbloc) {
fprintf(stderr, "warning!: srcbloc = destbloc\n");
exit(1);
}
if (offset < 0) {
fprintf(stderr, "warning!: offset = %i\n", offset);
}
if (len < 0) {
fprintf(stderr, "warning!: len = %i\n", len);
}

我想知道当这个程序运行时是否会测试所有的 if 语句?

最佳答案

给定您的代码

if (srcbloc == NULL) { /* <-- if this block is entered then, */
fprintf(stderr, "warning!: memrip source is null!\n");
exit(1); /* <-- Program will exit */
}
if (destbloc == NULL) { /* <-- Allocate destbloc of len length. */
destbloc = malloc(len);
}
if (srcbloc == destbloc) { /* <-- if this block is entered then, */
fprintf(stderr, "warning!: srcbloc = destbloc\n");
exit(1); /* <-- Program will exit */
}
if (offset < 0) {
fprintf(stderr, "warning!: offset = %i\n", offset);
}
if (len < 0) {
fprintf(stderr, "warning!: len = %i\n", len);
}

因此,如果 (srcbloc == NULL)(srcbloc == destbloc) 程序将发出警告(并退出)。如果任何其他测试匹配,将打印警告,但程序将继续处理。

关于连续 if 语句流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23728715/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com