What are the similarties/differences between a C++ reference and a C# reference ?
Edit:
I'm talking about Object references,as I'm a newbie I was unaware that such a simple line would cause ambiguity,as I have read. Whenever the term "reference" is used,its in context to Object reference,otherwise its explicitly quoted as "managed references".
I think all the people who have answered this question have got what I was trying to say and I made a comment that states clearly what I wanted to ask. I don't see any reason for a downvote,come on guys.
This question does not deserve to be closed.As newbies like me can learn from the insight a lot of experienced people have provided.
References are used to refer an existing variable in another name whereas pointers are used to store address of variable. References cannot have a null value assigned but pointer can. A reference variable can be referenced by pass by value whereas a pointer can be referenced by pass by reference.
No, it doesn't.
The call by reference method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. It means the changes made to the parameter affect the passed argument.
Pointers: A pointer is a variable that holds the memory address of another variable. A pointer needs to be dereferenced with the * operator to access the memory location it points to. References: A reference variable is an alias, that is, another name for an already existing variable.
C# references are closer to C++ pointers than to C++ references.
C# references can be null and have assignment semantics similar to pointers. The difference is that they are black boxes(you can't convert them to integral types) and you can't do arithmetic on them. They also can only point to reference types.
C++ references are quite different(apart from being compiled to pointers too). They are closer to .net managed references which are used for ref
parameters. But even then the assignment semantics differ.
Initialization of a reference is something quite different from assignment to it. Despite appear- ances, no operator operates on a reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With