Department of Engineering

IT Services

Assignment statements

Assignment statements assign a value to a variable. The general form is:

        <variable> = <expression>;

In general the type of the expression need not be the same as the type of the variable, but there are complex rules covering the automatic conversions which occur. A straightforward example is that int values can be assigned directly to floats. If a float value is assigned directly to an int variable it will be converted into an integer, usually by truncation not rounding.