The article illustrates the working of the different relational operator on the array STL. The **equality comparison ( == )** is performed by comparing the elements sequentially using operator ( == ), stopping at the first mismatch.

The **less-than comparison ( < )** or **greater-than comparison ( > )** behaves as if using algorithm lexicographical_compare, which compares the elements sequentially using operator () in a reciprocal manner (i.e., checking both a<b and b<a) and stopping at the first occurrence.

The implementation of relational operators on the array help us to compare between the data stored in different arrays.

**Equivalent operators : **Here are some operators whose work is same.

(a != b) is equivalent to !(a == b) (a > b) equivalent to (b < a) (a <= b) equivalent to !(b < a)

**Time Complexity :** The time complexity of the above operation is **O(n)** where n is the size of the array.

Below is the code to illustrate the working of relational operators on array

**Program 1:** Relational Operator Comparison

`// array comparisons using relational operators ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `int` `main() ` `{ ` ` ` `// declaration of array ` ` ` `array<` `int` `, 5> a = { 1, 2, 3, 4, 5 }; ` ` ` `array<` `int` `, 5> b = { 1, 2, 3, 4, 5 }; ` ` ` `array<` `int` `, 5> c = { 5, 4, 3, 2, 1 }; ` ` ` ` ` `if` `(a >= b) { ` ` ` `cout << ` `"a is greater than equal to b\n"` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `cout << ` `"a is neither greater than nor equal to b\n"` `; ` ` ` `} ` ` ` ` ` `if` `(b < c) { ` ` ` `cout << ` `"b is less than c\n"` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `cout << ` `"b is not lesser than c\n"` `; ` ` ` `} ` ` ` `if` `(a >= c) { ` ` ` `cout << ` `"a is greater than equal to c\n"` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `cout << ` `"a is neither greater than nor equal to c\n"` `; ` ` ` `} ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output :**

a is greater than equal to b b is less than c a is neither greater than nor equal to c

**Program 2:** Relational Operator Equality

`// CPP program to check for array qualities. ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `int` `main() ` `{ ` ` ` `// declaration of array ` ` ` `array<` `char` `, 5> a = { ` `'a'` `, ` `'b'` `, ` `'c'` `, ` `'d'` `, ` `'e'` `}; ` ` ` `array<` `char` `, 5> b = { ` `'e'` `, ` `'d'` `, ` `'c'` `, ` `'b'` `, ` `'a'` `}; ` ` ` `array<` `char` `, 5> c = { ` `'a'` `, ` `'b'` `, ` `'c'` `, ` `'d'` `, ` `'e'` `}; ` ` ` ` ` `if` `(a == b) { ` ` ` `cout << ` `"a is equal to b\n"` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `cout << ` `"a is not equal to b\n"` `; ` ` ` `} ` ` ` ` ` `if` `(b != c) { ` ` ` `cout << ` `"b is not equal to c\n"` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `cout << ` `"b is equal to c\n"` `; ` ` ` `} ` ` ` `if` `(a == c) { ` ` ` `cout << ` `"a is equal to c\n"` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `cout << ` `"a is not equal to c\n"` `; ` ` ` `} ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output :**

a is not equal to b b is not equal to c a is equal to c

Rated as one of the most sought after skills in the industry, own the basics of coding with our **C++ STL** Course and master the very concepts by intense problem-solving.

## Recommended Posts:

- Comparing String objects using Relational Operators in C++
- unordered_set operators in C++ STL
- Set a variable without using Arithmetic, Relational or Conditional Operator
- Difference between Relational operator(==) and std::string::compare() in C++
- Sorting an array according to another array using pair in STL
- array::front() and array::back() in C++ STL
- array::fill() and array::swap() in C++ STL
- array::begin() and array::end() in C++ STL
- array::crbegin() and array::crend() in C++ STL
- array::cbegin() and array::cend() in C++ STL
- array::rbegin() and array::rend() in C++ STL
- What are the operators that can be and cannot be overloaded in C++?
- Increment (Decrement) operators require L-value Expression
- Order of operands for logical operators
- Advanced C++ | Conversion Operators
- const_cast in C++ | Type Casting operators
- Bitwise Operators in C/C++
- How to sum two integers without using arithmetic operators in C/C++?
- Execution of printf with ++ operators
- Conditionally assign a value without using conditional and arithmetic operators

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.