数学幂运算符未按预期工作 [英] mathematical power operator not working as expected

查看:65
本文介绍了数学幂运算符未按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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"时,得到以下输出:

When I enter '2 2', I get this output:

2 ^ 2为0.

2^2 is 0.

为什么?如果有任何重要意义,我将在Eclipse中使用MinGW GCC编译器.

How come? I'm using the MinGW GCC compiler in Eclipse, in case that's of any importance.

推荐答案

^不是C中的数学幂运算符,它是 pow函数,该函数需要两个加倍.

^ is not the mathematical power operator in C, it's the bitwise exclusive-OR operator. You probably want the pow function, which takes two doubles.

这篇关于数学幂运算符未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆