Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Relational operator
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Ordering== ''Greater than'' and ''less than'' comparison of non-numeric data is performed according to a sort convention (such as, for text strings, [[lexicographical order]]) which may be built into the programming language and/or configurable by a programmer. When it is desired to associate a numeric value with the result of a comparison between two data items, say ''a'' and ''b'', the usual convention is to assign −1 if a < b, 0 if a = b and 1 if a > b. For example, the C function <code>[[strcmp]]</code> performs a [[three-way comparison]] and returns −1, 0, or 1 according to this convention, and [[qsort]] expects the comparison function to return values according to this convention. In [[sorting algorithm]]s, the efficiency of comparison code is critical since it is one of the major factors contributing to sorting performance. Comparison of programmer-defined [[data type]]s (data types for which the programming language has no in-built understanding) may be carried out by custom-written or library functions (such as <code>strcmp</code> mentioned above), or, in some languages, by ''[[Operator overloading|overloading]]'' a comparison operator β that is, assigning a programmer-defined meaning that depends on the data types being compared. Another alternative is using some convention such as member-wise comparison.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)