简体   繁体   English

当我执行以下代码时,没有输出,可能是什么原因?

[英]When I execute the following code, there is no output, what could be the cause?

Here is my C code.这是我的 C 代码。 I am not getting any output.我没有得到任何输出。 Please help.请帮忙。 I also tried adding the initialization of inside the main function, then also I am not getting any output.我也尝试在 main 函数内部添加初始化,然后我也没有得到任何输出。

#include <stdio.h>

int x = 10;
int main()
{
    if (x = 20)
    {
        x = -1;
    }
    else
    {
        printf("x not eqaul to 20\n");
    }
    if (x > 0)
    {
       printf("x not greather than 0\n");
    }
    else
    {
        /* notjing */
    }
    return 0;
}

So in the first if -statement you wrote if(x=20) .所以在第一个if语句中你写了if(x=20) This is not a conditunal argument, this is a mathematical operand.这不是一个条件参数,这是一个数学操作数。

So x will be set to 20;所以x将被设置为 20; afterworths it will be set to -1. afterworths 将设置为 -1。 And no printf() will be called.并且不会调用printf()

If think you wanted to use if(x==20) .如果认为您想使用if(x==20)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM