相关疑难解决方法(0)

C中的"&&"和"和"运算符

我试图计算两个整数的最大公分母.

C代码:

#include <stdio.h>

int gcd(int x, int y);

int main()
{
    int m,n,temp;
    printf("Enter two integers: \n");
    scanf("%d%d",&m,&n);
    printf("GCD of %d & %d is = %d",m,n,gcd(m,n));
    return 0;  
}

int gcd(int x, int y)
{
    int i,j,temp1,temp2;

    for(i =1; i <= (x<y ? x:y); i++)
    {
        temp1 = x%i;
        temp2 = y%i;
        if(temp1 ==0 and temp2 == 0)
            j = i;
    } 
    return j;         
}
Run Code Online (Sandbox Code Playgroud)

在if语句中,请注意逻辑运算符.它and不是&&(错误地).代码工作时没有任何警告或错误.

andC中是否有运营商?我正在使用 orwellDev-C++ 5.4.2(在c99模式下).

c operators logical-operators

22
推荐指数
4
解决办法
7428
查看次数

if(NULL ==指针)和if(指针== NULL)之间有什么区别?

使用有什么区别:

if (NULL == pointer) 
Run Code Online (Sandbox Code Playgroud)

和使用:

if (pointer == NULL)    
Run Code Online (Sandbox Code Playgroud)

我的教授说使用前者而不是后者,但我看不出两者之间的区别.

c++ coding-style conditional-statements

8
推荐指数
2
解决办法
1208
查看次数