Why is the output C, and after the value in the if is assigned, the statement under if is not execut

Updated on technology 2024-02-09
22 answers
  1. Anonymous users2024-02-05

    public class test1{

    public static void main(string args)

    boolean b = true;

    if(b=false) b=false is assigning a value to b, and this line ** is assigning a value first to make a judgment, at this time b is false, and it does not enter the branch.

    a");else if(b)

    b");else if(!b) //b = false !b is true, goes into the branch, and outputs c

    c");else "d");

  2. Anonymous users2024-02-04

    1. If (b=false) is equivalent to if((b=false)) is equivalent to if(true == (b=false)), because b has been assigned to false, so this condition is not valid, so it is judged down.

    2. Because b is already false at this time, else if (b) is not valid, continue to judge.

    3、else if (!b) holds, so output c.

    If replaced with if (b==false), then:

    1. Because b is true at this time, if (true==false) is not valid, continue to judge.

    2. else if (b) is true, so output b.

    Here the main distinction is that one equal sign is an assignment statement, and two equal signs are a statement to determine whether it is equal.

    If you are afraid of a clerical error, you can write if (false == b) like this, at this time, if you accidentally miss an equal sign, then the grammatical error can be distinguished at a glance.

  3. Anonymous users2024-02-03

    If and else will only execute one of them, not both.

  4. Anonymous users2024-02-02

    How does this ** feel that there is a problem, what you meant was to say, if A is equal to C, output C, don't wait for output B?

  5. Anonymous users2024-02-01

    The copy expression x=5 itself has a value, and this value is equal to the lvalue. In other words, the value of the formula x=5 is x, which means that it is 5. The answer value of the formula x=5 is 5 is not zero, which is true, and k=2 will be executed.

    Generally speaking, the statement after if prohibits the use of single equals signs, that is, assignment numbers, in order to prevent errors.

    If it is x=0, the value of this expression is 0, which is false, and the following statement will not be executed. It doesn't matter what software you compile with, it's dev or vs08.

  6. Anonymous users2024-01-31

    The assignment statement is always true copy, so it should be executed.

    Excellent programmers need to develop good habits, Du is best to judge that the statement is written as zhiif(5==x), even if the wrong dao input is missing a "=", that is, if(5=x), so that the compilation will report an error, if it is written as if(x==5), and the wrong input is if(x=5), the program will continue, and it will be difficult to check the error of the big program.

  7. Anonymous users2024-01-30

    Personally, I feel that the "=" here is the assignment symbol, and the value after the equal sign is assigned to x, so that if must be true, and then because the condition of if is true, it is normal to output the value of k, personal opinion.

  8. Anonymous users2024-01-29

    For the if statement, since bai

    You know the inside du

    The judgment statement is an expression, so when you want to assign a value to a variable in the statement, you should know the rules of assignment! Assignment is not the same as when it is equal! As you asked:

    if(x=5) this is wrong, the compiler is not going to agree with such an expression, so it is considered false, do not execute k=2, the same as below!

  9. Anonymous users2024-01-28

    The assignment operation returns an lvalue.

    x=5 returns 5 true

    x=0 returns 0 false

  10. Anonymous users2024-01-27

    Either zero is true, eg.

    if(a=5)

    else d=3;

    This statement has no syntax errors (there may be warnings) and is executable.

    But this statement never gets a chance to execute the else part.

    The result of the a=5 assignment expression is 5, when this expression appears in the position of the logical expression of the if statement, its calculation result is treated as a logical value, in the C language, the integer number is used to represent the logical quantity, and the non-zero represents "true", so this is a permanent true formula; The logical condition of this if is never false.

    In other words, the logical condition expressed here is not "whether the content of a is equal to 5", but the data 5 is fed into variable a.

  11. Anonymous users2024-01-26

    Not necessarily, depending on whether the value assigned to the variable is 0 or not

    Try the following programs:

    #include

    void main()

    The program outputs i=1, which means that the execution of the second if statement is executed.

  12. Anonymous users2024-01-25

    It's to compile and see if there are any syntax errors!

    If it is an assignment statement, the if statement is true.

    If you have a value of 0, you can try it yourself.

  13. Anonymous users2024-01-24

    No, only syntax compilation errors will occur, and if you can only use to determine whether it is equal or not.

  14. Anonymous users2024-01-23

    Your current conditional statement is written as 2 statements:

    Conditional statement a:if (xconditional statement b:if (x==y &&y==z) else executes conditional statement a, and the condition is satisfied Execute output statement 1;

    Then execute the conditional statement b, the condition is not satisfied, and the output statement 3 is executed;

    Let's change it to a statement with else if:

    if (xelse if (x==y &&y==z) else ;

    In this way, x

  15. Anonymous users2024-01-22

    Don't hesitate yet, the answer is: d

    Listen to me tell you about if(expressions, literals, constants, variables, etc.); As long as one of these final values is not 0, it means that the statement associated with if will not be executed, and it will be executed if it is not 0 anyway.

    According to the above: the if statement in the question '''associates'' printf('***');Then the if() parentheses are obviously an assignment expression, which means that if will use the final value of x as the basis for whether the if-associated statement is executed.

    It is clear that x=y+z; Final x = 0;

    So the else statement part is executed

  16. Anonymous users2024-01-21

    Expressing the abusive tenacity of high-end goods.

  17. Anonymous users2024-01-20

    ######;Because both y and z are 0; So the return value of the assignment statement is 0;

  18. Anonymous users2024-01-19

    First of all, make sure that the number you entered can be correctly assigned to the variable x, according to the way you write it in scanf, it should be x520.

  19. Anonymous users2024-01-18

    Because your judgment condition is and, you must have a number that satisfies 5,8,13 divisibility = 0 at the same time before it will be in the if statement.

  20. Anonymous users2024-01-17

    Is there a number that is divisible by 5 8 13 at the same time ? Replace && with ||Look.

  21. Anonymous users2024-01-16

    I don't have a problem.,It's best to use semicolons between assignment expressions.,Although I tried the answer, it didn't matter.,I don't know yours.,How did it start.,Just use you**.,I'm normal on this.。

  22. Anonymous users2024-01-15

    It runs on my machine without any problems.

Related questions
20 answers2024-02-09

There is an output after the ultimate. The main thing is to create opportunities, team battle contributions, area damage, and ignore armor to increase output.

15 answers2024-02-09

We can't see the eighty yet! It's much bigger than us, and it's kind to criticize us.

9 answers2024-02-09

Floppy disk error. CMOS Checksum Error - Loading default settings. >>>More

11 answers2024-02-09

First, it may be the blue screen caused by the incompatible lock of your graphics card, it is recommended that you uninstall the graphics card driver in safe mode and install the driver on the free drive disk of your computer's graphics card. >>>More

15 answers2024-02-09

It's because the girl was in a car accident when she was a child, which caused damage to her vocal cords, and because she was in the voice change period, her voice became like that! It's not something you were born with! Moreover, it is not genetic, and her family does not have a baby voice! I also have a baby voice! >>>More