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
Side effect (computer science)
(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!
== Example == One common demonstration of side effect behavior is that of the [[assignment operator]] in [[C (programming language)|C]]. The assignment <code>a = b</code> is an expression that evaluates to the same value as the expression <code>b</code>, with the side effect of storing the [[value (computer science)#lrvalue|R-value]] of <code>b</code> into the [[value (computer science)#lrvalue|L-value]] of <code>a</code>. This allows multiple assignment: <syntaxhighlight lang="c"> a = (b = 3); // b = 3 evaluates to 3, which then gets assigned to a </syntaxhighlight> Because the operator [[operator associativity#Right-associativity of assignment operators|right associates]], this is equivalent to <syntaxhighlight lang="c"> a = b = 3; </syntaxhighlight> This presents a potential hangup for novice programmers who may confuse <syntaxhighlight lang="c"> while (b == 3) {} // tests if b evaluates to 3 </syntaxhighlight> with <syntaxhighlight lang="c"> while (b = 3) {} // b = 3 evaluates to 3, which then casts to true so the loop is infinite </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)