, >=, ==, !=". Relational operators are all binary operators, and their function is to determine the relationship between the two expressions; the priority of relational operators is lower than that of arithmetic operators and higher than that of assignment operators; their operation results are only 0 or 1. When the condition is true, the result is 1; when the condition is not true, the result is 0."/> , >=, ==, !=". Relational operators are all binary operators, and their function is to determine the relationship between the two expressions; the priority of relational operators is lower than that of arithmetic operators and higher than that of assignment operators; their operation results are only 0 or 1. When the condition is true, the result is 1; when the condition is not true, the result is 0.">

Home >Backend Development >C#.Net Tutorial >What are the symbols for relational operations in C language?

What are the symbols for relational operations in C language?

烟雨青岚
烟雨青岚Original
2020-07-08 09:44:3015120browse

c language relational operation symbols include ", >=, ==, !=". Relational operators are all binary operators, and their function is to determine the relationship between the two expressions; the priority of relational operators is lower than that of arithmetic operators and higher than that of assignment operators; their operation results are only 0 or 1. The result is 1 when the condition is true, and 0 when the condition is not true.

What are the symbols for relational operations in C language?

##c language relational operation symbols include , >=, ==, !=.

The function of the relational operator is to determine the relationship between the two expressions. Note that this is to determine the size relationship, not other relationships.

What are the symbols for relational operations in C language?

# Relational operators are all binary operators, and their associativity is left associative. Relational operators have lower precedence than arithmetic operators and higher than assignment operators. Among the six relational operators, , >= have the same precedence, which is higher than == and !=, and == and != have the same precedence.

The operation result of relational operators is only 0 or 1. When the condition is true, the result is 1, and when the condition is not true, the result is 0

#include <stdio.h>
int main(){
    char c=&#39;k&#39;;
    int i=1, j=2, k=3;
    float x=3e+5, y=0.85;
    int result_1 = &#39;a&#39;+5<c, result_2 = x-5.25<=x+y;
    printf( "%d, %d\n", result_1, -i-2*j>=k+1 );
    printf( "%d, %d\n", 1<j<5, result_2 );
    printf( "%d, %d\n", i+j+k==-2*j, k==j==i+5 );
    return 0;
}

Running result:


1, 0
1, 1
0, 0

For expressions containing multiple relational operators, such as k==j= =i 5, according to the left associativity of the operator, first calculate k==j, this expression is not established, and its value is 0, and then calculate 0==i 5, it is not established, so the expression value is 0.


It should be reminded that == means equal, and = means assignment. You should pay attention to the distinction and avoid confusion.

Recommended tutorial: "

C Language"

The above is the detailed content of What are the symbols for relational operations in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn