Category: 

What is an Assignment Statement?

Article Details
  • Written By: Jessica Susan Reuter
  • Edited By: Allegra J. Lingo
  • Last Modified Date: 03 December 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
The Argentinian resort town of EpecuĂ©n was submerged by flooding for years; it is now populated by one elderly man.  more...

December 5 ,  1933 :  Prohibition ended in the US.  more...

An assignment statement is a computer language construct that binds a particular value to a computer variable. It is a ubiquitous construct in both programming and scripting languages, allowing data to be temporarily saved inside a program for future use. This is an important part of computer programming because if data could not be temporarily saved in some form, it would be impossible for a program to do anything useful.

Any type of value can be bound to a variable using an assignment statement, be it a complex object or a simple type like an integer or string of characters. The types of values which can be bound depend on the computer language being used, since some languages contain types that others lack. Regardless of the data value being assigned, an assignment statement always works the same way, associating data with a specific variable in machine code. Exactly how this happens can depend on the computer language being used, but programmers are never required to handle this process in source code.

Most assignment statements are written with the simple variable = value syntax. This is the most common syntax for assignments, although certain languages allow different syntaxes. In the Postscript language, for example, a value is assigned to a variable using the syntax /variable value def. There are a few other languages which also have alternative syntaxes, but assigning values to variables using an equals sign is nearly universal.

Ad

Writing an assignment statement does not always guarantee that a value will be properly bound to a variable. There are some computer languages in which programmers can employ specific keywords to prevent reassignment of a variable once it has been bound to a value. The usage and names of these keywords differ between languages, though they serve the same function. On occasion, errors in memory can also cause assignment statements to fail. These don't happen often if a program is carefully written, but they are still possible if the program unexpectedly runs out of memory or encounters another serious problem.

In some computer languages, an equals sign may be used for other things instead of an assignment statement. The most common alternate usage of an equals sign is to redefine its action, which could potentially create drastic differences in the mechanisms of an ordinary assignment statement. It is possible to redefine other symbols to restore assignment statement capabilities, but this is often a very complex undertaking. These reassignments are rarely needed in programming, and should usually be avoided unless absolutely necessary.

Ad

You might also Like

Recommended

Discuss this Article

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email