Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
you use the ref keyword if you want to pass the reference, otherwise a copy of the reference is passed by value. Maybe your teacher was right.
-
inaba45897yIt's still a reference though. Had it been passed by value this wouldn't print 3.
That's why it's called a reference type 😂😂 -
If a was a reference then doing a = new int[x] inside BBB would affect a inside main also, but that does not happen
-
inaba45897y@NOOB4LIFE No, that's just plain wrong. And I will let the docs explain why: https://docs.microsoft.com/en-us/...
"With value types, each variable has its own copy of the data, and it is not possible for operations on one variable to affect the other"
This means exactly what happens in the picture I posted above. That a will be a reference to aa, and in other words, it's a god damn reference. -
matt-jd10097y@vlatkozelka but if the point p is changed outside of the method whilst executing the method. The value of p in your method random would then be affected as well both in java and c#
-
inaba45897y@NOOB4LIFE I.. Uhm.. I think you might need a back to basic.. Or to rethink your statement 😂
-
inaba45897y@vlatkozelka ..seriously
Okay, so, look at this picture. The fact that this happens means that it is not passed as a value but as a reference. You don't get any more proof than that.
And yes, I can link to the docs, and keep in mind that this is the docs of the people that made the god damn language, and then say that it's how it is because, it's the god damn documentation. If he meant something else he would have said it after I told him a copy would be made, but he didn't. He still insisted on it being passed as a value.
Either way, what he meant doesn't matter when what he said wasn't that -
inaba45897y@vlatkozelka congratulations. You've modified the pointer to be a pointer to something different. That does not make it pass by value at all.
And my example isn't pointless wtf. How Hugh are you at the moment? They've perfectly demonstrated just what I meant.
If you in C++ do this:
void foo(std::vector<int>* p) {
p = nullptr;
}
The pointer p will be destroyed, but whatever p points to will be intact. Just like in your example. And just like in your example, that does not make it pass by value.
Related Rants
Today I had an, argument with my C# teacher because he believes that reference types are passed by value
I posted a link on Facebook to MSDNs page about it, but somehow some guy in my class still argued for it being pass by value. The reason he says so is because the value is the reference, even though it's quite literally a reference.
It's a reference to a variable rather than, a value.
Kindly
Fuck
Off
rant
i'm shit
teacher is shit
school is shit
shit
fuck this