Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous
Next: Blocks Up: C++ Summary Previous: Predefined functions

   
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.
© Cambridge University Engineering Dept
Information provided by Tim Love
2006-12-08