当我尝试这个时,为什么这个功能给出了错误的答案-1而不是正确的答案1?myPow(-1.00000, -2147483648)
double QuickPower(double x, int n)
{
if(n==0){
return 1;
}
if(n==1){
return x;
}
if(n>=2){
int res=n%2;
double half=QuickPower(x,n/2);
return res? Half*half*x: half*half;
}
}
double myPow(double x, int n) {
return n>=0? QuickPower(x,n):(1/QuickPower(x,-n));
}
Run Code Online (Sandbox Code Playgroud)
我只是尝试运行下面的代码.打印出"Hello World".这里我没有指定数据类型,但它仍然传递if语句.为什么?
if (-1 > 2147483648)
{
cout << "Hello World";
}
编写代码来反转C风格的字符串.(C风格的字符串表示"abcd"表示为五个字符,包括空字符.)没有打印出来.为什么?
void ReverseString(char *p){
int length = strlen(p);
for (int i = 0, j = length; i < j; i++, j--){
swap(p[i], p[j]);
}
}
int main()
{
char a[] = "12345";
ReverseString(a);
cout << a;
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)