Home > Blockchain >  When I execute the following code, there is no output, what could be the cause?
When I execute the following code, there is no output, what could be the cause?

Time:10-24

Here is my C code. 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.

#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;
}

CodePudding user response:

So in the first if-statement you wrote if(x=20). This is not a conditunal argument, this is a mathematical operand.

So x will be set to 20; afterworths it will be set to -1. And no printf() will be called.

If think you wanted to use if(x==20).

  • Related