
January 23rd, 2003, 05:38 AM
|
|
Junior Member
|
|
Join Date: Dec 2002
Location: Budapest
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
not correct 100%
I think, your assumption is not correct 100%:
1. here, there is 80% truth. yes, Reference is a kind of alias for another variable. Yes, youi can create a reference to a variable and use that reference in the same way. But, you have to remember, that you cannot create reference without creating and initializing variable first, otherwise you will get problem. More strcitly, reference is "syntactic sugar", it is a pointer which is always dereferenced for you.
and you cannot create 2 two variables sharing the same memory
with reference. you just create another names for that variable. but that names are pointers and their value is the address of original variable.
2. and it is union, which allows creating 2 variables "really" sharing the same memory. But only one can exist at the time.
Even if anonymous union contains two variables of same datatype
like, does not make sense, because when you will have 1 int space in memory.
The main reason to have union is to safe memory.
in this and it will not act in the same way as reference does. for example:
|