This section contains 303 words (approx. 2 pages at 300 words per page) |
A constant reference parameter is a term relevant to computer programming. The parameter allows a programmer to protect the data that has been sent to a function, so that the function cannot alter the data. This is possible because it is the address of the data that is actually sent to the function, not a copy of the data itself. When the function is executed, the data at the supplied address is used.
The preservation of data can also be achieved by the use of a so-called value mechanism. However, this latter mechanism requires more memory than does the use of a constant reference parameter, because it requires data to be copied. Since the constant reference parameter operates by supplying the address of data, not the data itself, less memory is required.
A constant reference parameter operates by the use of the modifier "const" in the encoded function definition. For example, the following function definition is a reference parameter, which can alter the value of the data it is commanded to obtain: void GetData (double &Num3, int &Num4). Any change made to the values referred to by the parameter nametags is also a change in the value referred to by the any arguments that are written. This is because the parameter and argument are directed to the same location in memory. In contrast, the function definition of a constant reference parameter would be written as: void GetDouble (double &Num3, const int &Num4). The use of the "const" designation has modified the function so that the data cannot be changed, by allowing the parameter and the argument to have the same memory location.
Constant reference parameters are utilized with programming components, primarily for structured object such as structs, classes, and arrays. Object-oriented languages such as C++ utilize constant reference parameters.
This section contains 303 words (approx. 2 pages at 300 words per page) |