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 syntax
(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!
===Evaluation order=== In any reasonably complex expression, there arises a choice as to the order in which to evaluate the parts of the expression: {{C-lang|(1+1)+(3+3)}} may be evaluated in the order {{C-lang|(1+1)+(3+3)}}, {{C-lang|(2)+(3+3)}}, {{C-lang|(2)+(6)}}, {{C-lang|(8)}}, or in the order {{C-lang|(1+1)+(3+3)}}, {{C-lang|(1+1)+(6)}}, {{C-lang|(2)+(6)}}, {{C-lang|(8)}}. Formally, a conforming C compiler may evaluate expressions in ''any'' order between ''[[sequence point]]s'' (this allows the compiler to do some optimization). Sequence points are defined by: * ''Statement ends'' at semicolons. * The ''sequencing operator'': a comma. However, commas that delimit function arguments are not sequence points. * The ''short-circuit operators'': logical ''and'' ({{code|&&}}, which can be read ''and then'') and logical ''or'' (<code>||</code>, which can be read ''or else''). * The ''[[?:|ternary operator]]'' ({{code|?:}}): This operator evaluates its first sub-expression first, and then its second or third (never both of them) based on the value of the first. * Entry to and exit from a ''function call'' (but not between evaluations of the arguments). Expressions before a sequence point are always evaluated before those after a sequence point. In the case of short-circuit evaluation, the second expression may not be evaluated depending on the result of the first expression. For example, in the expression {{C-lang|(a() {{!}}{{!}} b())}}, if the first argument evaluates to nonzero (true), the result of the entire expression cannot be anything else than true, so {{code|b()}} is not evaluated. Similarly, in the expression {{C-lang|(a() && b())}}, if the first argument evaluates to zero (false), the result of the entire expression cannot be anything else than false, so {{code|b()}} is not evaluated. The arguments to a function call may be evaluated in any order, as long as they are all evaluated by the time the function is entered. The following expression, for example, has undefined behavior: <syntaxhighlight lang=C> printf("%s %s\n", argv[i = 0], argv[++i]); </syntaxhighlight>
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)