This section contains 468 words (approx. 2 pages at 300 words per page) |
The assignment statement is the simplest expression in computer programming. Most programming languages use the conventional mathematical symbol = (the "equals" sign) to indicate assignment, but there are exceptions such as Pascal, which uses := (a colon and an "equals" sign).
In an assignment statement an expression is evaluated and the result stored in a variable in the program. The general form of the assignment statement is:
- result = expression
A very simple example of a real assignment statement is:
- int i = 3;
Although the number 3 is a constant, it is also an expression that evaluates to the number 3. At the end of the statement, the variable "i" contains this number. It is important to note that the data type that the expression evaluates to must be the same type as the result. Most languages have implicit conversion rules built into them to cope with converting between the primitive data...
This section contains 468 words (approx. 2 pages at 300 words per page) |