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
Assignment (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!
==Semantics== An assignment operation is a process in [[imperative programming]] in which different values are associated with a particular variable name as time passes.<ref name="2CS24">{{cite web|url=http://www.csc.liv.ac.uk/~frans/OldLectures/2CS24/declarative.html|title=2cs24 Declarative|website=www.csc.liv.ac.uk|access-date=20 April 2018|archive-url=https://web.archive.org/web/20060424045449/http://www.csc.liv.ac.uk/~frans/OldLectures/2CS24/declarative.html|archive-date=24 April 2006|url-status=dead}}</ref> The program, in such model, operates by changing its state using successive assignment statements.<ref name="weisskop"/><ref name="Flaig2008">{{cite book |author=Ruediger-Marcus Flaig |title=Bioinformatics programming in Python: a practical course for beginners |url=https://books.google.com/books?id=kS7Dye-dv54C&pg=PA98|access-date=25 December 2010 |year=2008 |publisher=Wiley-VCH |isbn=978-3-527-32094-3 |pages=98β99}}</ref> Primitives of imperative programming languages rely on assignment to do [[iteration#Computing|iteration]].<ref name="Bruce Tate"/> At the lowest level, assignment is implemented using [[assembly language|machine operations]] such as <code>MOVE</code> or <code>STORE</code>.<ref name="weisskop"/><ref name="Bruce Tate">[http://www.ibm.com/developerworks/java/library/j-cb07186.html Crossing borders: Explore functional programming with Haskell] {{webarchive |url=https://web.archive.org/web/20101119190821/http://www.ibm.com/developerworks/java/library/j-cb07186.html |date=November 19, 2010 }}, by Bruce Tate</ref> [[variable (programming)|Variables]] are containers for values. It is possible to put a value into a variable and later replace it with a new one. An assignment operation modifies the current state of the executing program.<ref name="Flaig2008"/> Consequently, assignment is dependent on the concept of [[variable (programming)|variables]]. In an assignment: * The <code>''expression''</code> is evaluated in the current state of the program. * The <code>''variable''</code> is assigned the computed value, replacing the prior value of that variable. Example: Assuming that <code>a</code> is a numeric variable, the assignment <code>a := 2*a</code> means that the content of the variable <code>a</code> is doubled after the execution of the statement. An example segment of [[C (programming language)|C]] code: <syntaxhighlight lang="c"> int x = 10; float y; x = 23; y = 32.4f; </syntaxhighlight> In this sample, the variable <code>x</code> is first declared as an int, and is then assigned the value of 10. Notice that the declaration and assignment occur in the same statement. In the second line, <code>y</code> is declared without an assignment. In the third line, <code>x</code> is reassigned the value of 23. Finally, <code>y</code> is assigned the value of 32.4. For an assignment operation, it is necessary that the value of the <code>''expression''</code> is well-defined (it is a valid [[value (computer science)|rvalue]]) and that the <code>''variable''</code> represents a modifiable entity (it is a valid modifiable (non-[[const]]) [[Value (computer science)|lvalue]]). In some languages, typically [[Dynamic programming language|dynamic]] ones, it is not necessary to declare a variable prior to assigning it a value. In such languages, a variable is automatically declared the first time it is assigned to, with the scope it is declared in varying by language.
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)