问题描述
#include <stdio.h>
int main (void)
{
int x = 10^2;
long a = 4000465006540123; //(16 places)
long b = 4000465006540123 % x;
printf("%li\n",b);
}
当我运行代码(正确编译)时,代码打印为“ 3”。不是应该打印出“ 23”,因为x是100,而不是10?
解决方法
int x = 10^2;
与int x = 8;
相同的^
是异或运算符。
使用int x = 100;
或10*10
。
注意:在C语言中,%
是 remainder 运算符,而不是 modulus 运算符。 a%b
中的Negative results在a < 0
时出现。