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
C (programming language)
(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!
=== Operators === {{Main|Operators in C and C++}} C supports a rich set of [[Operator (computer programming)|operators]], which are symbols used within an [[Expression (computer science)|expression]] to specify the manipulations to be performed while evaluating that expression. C has operators for: * [[arithmetic]]: [[Addition|<code>+</code>]], [[Subtraction|<code>-</code>]], [[Multiplication|<code>*</code>]], [[Division (mathematics)|<code>/</code>]], [[Modulo operation|<code>%</code>]] * [[Assignment (computer science)|assignment]]: <code>=</code> * [[augmented assignment]]: {{codes|+{{=}}|-{{=}}|*{{=}}|/{{=}}|%{{=}}|&{{=}}|{{!}}{{=}}|^{{=}}|<<{{=}}|>>{{=}}|d=,{{space}}}} * [[bitwise logic]]: <code>~</code>, <code>&</code>, <code>|</code>, <code>^</code> * [[bitwise shift]]s: <code><<</code>, <code>>></code> * [[Boolean logic]]: <code>!</code>, <code>&&</code>, <code>||</code> * [[?:|conditional evaluation]]: [[?:|<code>? :</code>]] * equality testing: [[Equality (mathematics)|<code>==</code>]], [[Inequality (mathematics)|<code>!=</code>]] * [[Subroutine|calling functions]]: <code>( )</code> * [[Increment and decrement operators|increment and decrement]]: <code>++</code>, <code>--</code> * [[Record (computer science)|member selection]]: <code>.</code>, <code>-></code> * object size: <code>[[sizeof]]</code> * type: <code>[[typeof]]</code>, <code>typeof_unqual</code> ''since C23'' * [[order relation]]s: <code><</code>, <code><=</code>, <code>></code>, <code>>=</code> * [[Pointer (computer programming)|reference and dereference]]: <code>&</code>, <code>*</code>, <code>[ ]</code> * sequencing: [[Comma operator|<code>,</code>]] * [[Order of operations#Programming languages|subexpression grouping]]: <code>( )</code> * [[type conversion]]: <code>(''typename'')</code> C uses the operator <code>=</code> (used in mathematics to express equality) to indicate assignment, following the precedent of [[Fortran]] and [[PL/I]], but unlike [[ALGOL]] and its derivatives. C uses the operator <code>==</code> to test for equality. The similarity between the operators for assignment and equality may result in the accidental use of one in place of the other, and in many cases the mistake does not produce an error message (although some compilers produce warnings). For example, the conditional expression <code>if (a == b + 1)</code> might mistakenly be written as <code>if (a = b + 1)</code>, which will be evaluated as <code>true</code> unless the value of <code>a</code> is <code>0</code> after the assignment.<ref name="AutoTX-8">{{cite web |url=http://www.cs.ucr.edu/~nxiao/cs10/errors.htm |title=10 Common Programming Mistakes in C++ |website=Cs.ucr.edu |access-date=June 26, 2009 |archive-date=October 21, 2008 |archive-url=https://web.archive.org/web/20081021080953/http://www.cs.ucr.edu/~nxiao/cs10/errors.htm |url-status=live }}</ref> The C [[operator precedence]] is not always intuitive. For example, the operator <code>==</code> binds more tightly than (is executed prior to) the operators <code>&</code> (bitwise AND) and <code>|</code> (bitwise OR) in expressions such as <code>x & 1 == 0</code>, which must be written as <code>(x & 1) == 0</code> if that is the coder's intent.<ref name="AutoTX-9">{{cite book |title=C and the 8051 |edition=3rd |last1=Schultz |first1=Thomas |year=2004 |publisher=PageFree Publishing Inc. |location=Otsego, MI |isbn=978-1-58961-237-2 |page=20 |url={{GBurl|id=rI0c8kWbxooC|pg=PT47}} |access-date=February 10, 2012 }}</ref>
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)