PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 16, 2022

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

 August 16, 2022     c, output     No comments   

Issue

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

Solution

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).



Answered By - alen
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing