c Language if Statement Question

Asked 2 years ago, Updated 2 years ago, 51 views

There are times when you get confused by the conditional expression in the if statement.

if(num%10) ~~~~

else ~~~~

If I divide num by 10 and I can't find the rest, do I go to else? How do I understand?

c if문

2022-09-21 12:43

1 Answers

In the if statement, execute the code corresponding to the if statement if the expression in parentheses is true, or in the if statement if false.

However, when we first developed the c language, instead of separating the type that corresponds to true lies, we expressed falsehoods with 0 and 1.

I don't know the exact operating principle, but if the expression in parentheses in the if statement is 0, the conditional statement is judged to be false and does not execute the codes below, and in all other cases, it seems to be true and execute the codes below.

In other words, if the value of num%10 you wrote in the question is 0, the conditional statement (although it is not strictly a conditional statement) is judged to be false, and in all other cases, the if statement is executed.


2022-09-21 12:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.