"Learning Notes", "C language" relational operators

Source: Internet
Author: User

1. Conditional judgment

By default, every line of code that we write in the program will be executed. But most of the time, we want to execute a piece of code when a certain condition is established.

This situation can be done using conditional statements, but we do not study conditional statements for the time being, first look at some more basic knowledge: How to judge a condition is not tenable.

2. True and False

In C language, the condition is called "true", the condition is not established is called "false", therefore, the judgment condition is established, is the judgment condition "true and false".

How to judge True and false? C language rules, any value is true and false, any non-0 value is "true", only 0 is "false". In other words, 108, 18, 4.5, 10.5, etc. are all "true" and 0 are "false".

3. Relationship Comparison

It is often compared in development, such as the size of the cards in the game of landlords. You can compare the size of two values by using the relational operator.

Relational operators result in only 2 of the results: if the condition is true, the result is 1, or "true", and if the condition is not true, the result is 0, or "false".

4. Use note

The precedence of the = =,! = in the relational operator equals,<, <=, >, >=, and the precedence of the former is lower than the latter: 2==3>1

The associative direction of the relational operator is "left to right": 4>3>2

The precedence of the relational operator is less than the arithmetic operator: 3+4>8-2

1#include <stdio.h>2 3 intMain ()4 {5     /*6 int a = ten;7     8 int b = one;9     Ten //condition is set to return 1, really One //conditions are not established on return 0, False A int result = b >= A; -      - printf ("%d\n", result); the      */ -      -     //int a = 2>3==1; -     //int a = 3+4 > 8-2; +      -     intA =5!=4+2*7>3==Ten; +      Aprintf"%d\n", a); at      -     return 0; -}

"Learning Notes", "C language" relational operators

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.