This documentation is archived and is not being maintained.

Treatment of Argument Types

Formal arguments declared as const types cannot be changed within the body of a function. Functions can change any argument that is not of type const. However, the change is local to the function and does not affect the actual argument's value unless the actual argument was a reference to an object not of type const.

The following functions illustrate some of these concepts:

// expre_Treatment_of_Argument_Types.cpp
// C2166 expected 
int func1( const int i, int j, char *c )
{
    i = 7;         // Error: i is const.
    j = i;         // OK, but value of j is
                   //  lost at return.
    *c = 'a' + j;  // OK: changes value of c
                   //  in calling function.

    return i;
}

double& func2( double& d, const char *c )
{
    d = 14.387;    // OK: changes value of d
                   //  in calling function.
    *c = 'a';      // Error: c is a pointer to
                   //  a const object.

    return d;
}

See Also

Postfix Expressions

Show: