Condition in if (condition) Statements

Source: Internet
Author: User

Compiling environment: Ubuntu 12.04: gccwindows XP: VS-2005

Let's take a deeper look at the condition in the IF (condition) statement, that is, when the condition is true and when it is false.

The main body of the test code is as follows:
int main(int argc, char *argv[]){if (CONDITION)printf("true.\r\n");elseprintf("false.\r\n");return 0;}
Situation 1:
Condition:
(1)/* true */
(0)/* false */
(-1)/* true */
Conclusion: 0 is false, and non-zero is true.

Situation 2:
Signed int value1 = 11;
Signed int value2 = 328;
Condition:
(Value1-value2)/* true-3rd cases in the same [scenario 1 */
(Value1-value2)> 2000)/* false */

Situation 3:
Unsigned int value1 = 11;
Unsigned int value2= 328;
Condition:
(Value1-value2)/* true-3rd cases in the same [scenario 1 */
(Value1-value2)> 2000)/* true */
This involves the" Implicit conversion(Value1-value2) is implicitly converted to the unsigned int type. The conversion method is the complement code of (value1-value2 ).
(Value2-value1)> 2000)/* false */

Situation 4:
Int value1 = 11;
Unsigned int value2= 328;
The result is the same as situation 3.
Implicit conversions of data types. If one of the operands is an unsigned int, the other operand is also considered as an unsigned Int.
(Value1-value2)/* true */
(Value1-value2)> 2000)/* true */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.