Reference (Reference) type

xiaoxiao2021-03-06  61

Reference type definition:

INT IVAL = 1024; INT & REFVAL = IVAL; // RightInt & Refval2; // Error. It Must Be Initialized

The reference type is different from the pointer:

INT & REFVAL = & IVAL; // Error

INT * PTR = & IVAL;

INT * & refval2 = Ptr; // Right. Refval2 is a reference to the pointer

Once defined, the reference type can no longer point to other objects, such as:

INT min_val = 0;

Refval = min_val; //, the value of IVAL is modified to 0 instead of refval pointing min_val

In fact, the reference type is equivalent to an alias alias

Real C programmers rarely use the reference type to independent object, the reference type is mainly used as a function of the function. such as

BOOL GET_NEXT_VAL (INT & NEXT_VAL);

Matrix Operator (Const Matrix &, Const Matrix &);

转载请注明原文地址:https://www.9cbs.com/read-118096.html

New Post(0)