gpt4 book ai didi

c - 数学幂运算符未按预期工作

转载 作者:太空狗 更新时间:2023-10-29 15:42:36 26 4
gpt4 key购买 nike

short sho1, sho2;
printf("Enter two shorts.\n");
scanf("%hd %hd", &sho1, &sho2);
printf("%hd^%hd is %hd.\n", sho1, sho2, sho1^sho2);

当我输入“2 2”时,我得到以下输出:

2^2 is 0.

怎么会?我在 Eclipse 中使用 MinGW GCC 编译器,以防它很重要。

最佳答案

^ 不是 C 中的数学幂运算符,它是 bitwise exclusive-OR operator .你可能想要 pow function ,这需要两个 double 。

关于c - 数学幂运算符未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2027877/

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