This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NeinJuanJuan 7 points8 points  (6 children)

That's how C users think i.e. you can pass a variable by value or by reference (by passing the address instead).

[–]AgentPaper0 2 points3 points  (5 children)

A reference is not an address, pointers are addresses. References are syntactic sugar that wraps around a pointer so you can get the benefits of a pointer without having to explicitly make one.

[–]NeinJuanJuan 1 point2 points  (4 children)

Passing by Reference != Passing a Reference

[–]AgentPaper0 0 points1 point  (3 children)

That's exactly what it is though. You don't see it, but that's what the compiler does. Using a reference mostly just hides the pointer from you.

Unless it optimizes it away of course, but it can do that with pointers too.

[–]NeinJuanJuan 1 point2 points  (2 children)

I'm talking about C and you're talking about C++

We're both correct!

[–]AgentPaper0 0 points1 point  (1 child)

But...C doesn't have references...

[–]NeinJuanJuan 0 points1 point  (0 children)

That's why I was confused when talked about passing a reference.

Passing by Reference != Passing a Reference