*& operator

Hello everyone! I'm in trouble at figuring out what that operator is , what does it mean , where can be used, its restrictions and its importance? I mean, don't tell me it is used for returning the reference or sth like that, because it seem to be really dim, as long as I can as well declare a pointer int *ptr and return ptr for its address.
Please try to not use any implementation or pointers terms because I'm a newbie as I mentioned above, but if you'd use layman's language would be just fine. Thank you very much!
There is no &* operator.

There are contexts in which using the & and * symbols together is meaningful. If you show us the context in which you've seen this, we'll be able to help you understand what it means.

And, yes, it will probably have something to do with references, pointers, or both.
Last edited on
ill give you the pointer run down, though.

imagine the ram of your computer is a single dimensional array of bytes.
you can think of a pointer as an index into that array. Its value means nothing, but its the spot where your data IS.

Address of, &, gives you that index from a non-pointer variable.

so int x;
int * p;
p = &x; .. p is now a pointer to x, as it stores the index in memory where x IS.

the type of the pointer (int *, double *, myclass *) tells you how much memory is at the location storing the item. That is why you have a type on it, really, when it comes down to mechanics. You know an int is 4 bytes, so you know p above is the first byte of 4 total.

That is all a reference is ... a reference is just a way to get a pointer to something that was not created using pointer stuff like new. Youll see them called handles in windows and some other programming, and its still just an address in memory at the end of the day.

The biggest 2 uses of & are for "reference" in a function and to get a pointer from something that was not originally a pointer.

you do this because some functions need a pointer, and you don't have one :)
void foo (int * I);
...
foo(&x);

and by references
void bar( int &I) //I is passed by pointer, or "reference", and by giving that memory location, the function can change the SAME memory location as the main program when referring to I, instead of a copy of it which is what is passed without the &. People sometimes pass large data types by reference to save making that copy, which is slow.





Where T is some type, the derived type T& is 'reference to T'
Where X is some type, the derived type X* is 'pointer to X'
Where Y is some type, the derived type Y*& is 'reference to pointer to y'

1
2
3
int i = 7 ; // type if i is 'int'
int* pi = &i ; // type of pi is 'pointer to int'
int*& rpi = pi ; // type of rpi is 'reference to int*' ie. 'reference to pointer to int' 
Topic archived. No new replies allowed.