Whats the difrence Pointer and Refrence

So what is the difrence betwen.
SomeStruct* StructOne;
and
SomeStruct & StructTwo; // Can not be null?
Last edited on
A pointer points to an object, while a reference is the object.
So in essence a pointer is the address and the reference is a representation of that object?
a pointer tells the location of an adress of a block of data. a reference is a well a reference to a block of data to manipulate and use it
So passing somthing by refrence &SomeObject is the same as just passing SomeObject.
With the difrence beeing &SomeObject is "safe" since the object must be initelized?
So passing somthing by refrence &SomeObject is the same as just passing SomeObject.
No.
1. Changes to the reference are reflected in the object.
2. No copies are made.

With the difrence beeing &SomeObject is "safe" since the object must be initelized?
No. A reference may point to an uninitialized object. The reference itself is guaranteed to be initialized. In other words, a reference will point to an object, unlike a pointer, which may point to nothing.

For pedagogic reasons, you can think of references as being equivalent to pointers except:
* You use . instead of ->
* A reference can't point to invalid memory.
Topic archived. No new replies allowed.