gpt4 book ai didi

c - MSVS 2017 : Pointer null check not behaving as it should

转载 作者:太空宇宙 更新时间:2023-11-04 06:51:36 26 4
gpt4 key购买 nike

<分区>

我写了下面的“Hello world!”级代码:

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

int main(const int argc, const char *argv[]) {
double *Bptr = NULL;
printf("Bptr's current value is: %p\n", Bptr);
double Barray = 1.02;
Bptr = &Barray;
if (Bptr == NULL); {printf("Bptr is still a null pointer: %p\n", Bptr); };
if (!Bptr); {printf("Bptr is still a null pointer (check 2): %p\n", Bptr); };
printf("The address of Bptr is: %p\n", Bptr);
return 0;
}

当我使用 Visual Studio 2017 构建并运行上述内容时,会产生以下奇怪的输出:

Bptr's current value is: 00000000
Bptr is still a null pointer: 00B3FD58
Bptr is still a null pointer (check 2): 00B3FD58
The address of Bptr is: 00B3FD58

不出所料,这不是我想要的。这是我第一次遇到这个问题。这也是我第一次将 MSVS 项目作为“空项目”而不是 Windows 控制台/桌面应用程序启动,因此我怀疑这可能与此有关。是否有人对可能导致此行为的原因有任何建议?

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