Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
C (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
C (programming language)
(section)
Add topic