# Relational operators in C

In real life, we often compare two different quantities and depending on their relation, we take some decisions. For example, we compare the price of two items, age of two persons etc. Relational operators supports these comparisons in C programming.

We use relational operators to compare two constants, variables or expressions. We generally compare two quantities of similar nature. Likewise, relational operators can only compare any two similar types. It evaluates Boolean value either true or false depending on their relation. Based on evaluated Boolean result we take decisions or execute some statements.

In C programming, there is no concept of Boolean values. C represents false with 0 and true with a non-zero integer value.

C supports six relational operators.

OperatorDescription
`>`Greater than
`<`Less than
`>=`Greater than or equal to
`<=`Less than or equal to
`==`Equals to
`!=`Not equal to

Let us demonstrate working of each relational operator.

Suppose x, y and z are three integer variables with initial values

`int x=10, y=5, z=10;`

Relational operationsResultDescription
`x > y`1`10 > 5` is true, therefore returns 1
`x < y`0`10 < 5` is false, therefore returns 0
`x >= z`1`10 ≥ 10` is true, therefore returns 1
`x <= y`0`10 ≤ 5` is false, therefore returns 0
`x == z`1`10 = 10` is true, therefore returns 1
`x != z`0`10 ≠ 10` is false, therefore returns 0

You are free to use any non-zero integer value to represent true. However, C standard specifies to use 1 for representing a true value.

Important note: Do not confuse assignment `=` operator with relational equals to `==` operator. Both are different and their working mechanism are different. Beginners always makes this common mistake of using `=` in place of `==`. Hence use these with cautious.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8024836,"math_prob":0.98753464,"size":1822,"snap":"2020-34-2020-40","text_gpt3_token_len":427,"char_repetition_ratio":0.12761275,"word_repetition_ratio":0.0477707,"special_character_ratio":0.25521407,"punctuation_ratio":0.114369504,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.986654,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-09-24T09:30:04Z\",\"WARC-Record-ID\":\"<urn:uuid:0859d462-032d-478e-aabe-dc908eaf3c04>\",\"Content-Length\":\"81349\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:378a83cf-c0e7-4e2f-ae7b-82812b728b52>\",\"WARC-Concurrent-To\":\"<urn:uuid:8c1cefff-6f89-4c01-8c0a-18b24f48cfa9>\",\"WARC-IP-Address\":\"52.86.133.10\",\"WARC-Target-URI\":\"https://codeforwin.org/2017/08/relational-operators-c.html\",\"WARC-Payload-Digest\":\"sha1:OUYNZJJJHS4XB222SB275KJSSINKAS54\",\"WARC-Block-Digest\":\"sha1:KEAHVQ3T3XNXNGWVSXJZPOBUZPNUVJQU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600400214347.17_warc_CC-MAIN-20200924065412-20200924095412-00373.warc.gz\"}"}