gpt4 book ai didi

c - 意外的输出,但代码没有错

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

<分区>

我尝试在 CodeBlocks(版本 13.12)上编译它。不知何故,指针在被 toupper() 调用之前递增

#include <stdio.h>
#include <ctype.h>


int main(void)
{
char str[80] = "the only way";
char *p;

p = str;

while(*p){
*p++ = toupper(*p);
}

printf(str);
return 0;
}

这导致输出“HE ONLY WAY”,而我正在寻找输出“THE ONLY WAY”。我在我的电脑上试过它给出了错误的输出。然而,当我在 friend 的计算机上尝试这段代码时,代码运行良好,给出了输出“THE ONLY WAY”。我的问题是为什么我的输出不同?P.s 如果我更换

*p++ = toupper(*p);

*p++ = toupper( *(p-1));

我得到了“THE ONLY WAY”的期望输出。

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