Kartik
Pass by reference (C++ only) - IBM Documentation https://www.ibm.com/docs/en/zos/2.4.0?topic=calls-pass-by-reference-c-only
You can go through this for better understanding of call by reference, there're some examples written too
Kevin
I WILL TRY
Kevin
it's confussing for me when i use arrays
Kartik
Yes. Even pointers are passed by value. So passing arguments by pointers is not pass by reference in C++
Pointers are passed by value... that's true. Pointers themselves are used as references to point toward the actual value I guess??
Anonymous
No... pointers are not passed by values, pointers are memory areas that is passed when you specify... that means the values stored in that memory area can be changed... by reference of where the value is stored in the memory. By value means when variable is passed as a number... like int 45 will be passed as 45, the function cannot change or modify that information.
Which is why I said you don't understand the semantics. In your example you did void fun(int* p) { *p = 5; // this changes underlying value p=0; // this does not change original pointer } int main(){ int a = 0; int* p = &a; fun(p); //a will change to 5 but p will not be 0 } It is because of this that passing by pointer exhibits "pass by value semantics". The pointed to variable does not determine the semantics. In this case it the parameter which is the pointer which determines whether it is pass by value or pass by reference semantics. In this case the pointer is passed by value. If you want to pass the pointer by reference, then the function will look like this int fun(int* &p){ *p = 5; p = 0; } Here both the pointed to value and the pointer will change. This is pass by reference semantics with pointer So in summary, YOU ARE WRONG!!!
Talula
English.
Anonymous
It is not passed by value...
It is. And if you keep arguing here without any factual statements to support it, I will have to ban you. Read my post before passing off inaccurate statements as accurate.
Talula
It is. And if you keep arguing here without any factual statements to support it, I will have to ban you. Read my post before passing off inaccurate statements as accurate.
Look, seriously I don't know what you have against me calling me stupid, and WRONG in caps... But passing by value simply means passing a value to a function... https://www.educative.io/edpresso/pass-by-value-vs-pass-by-reference
Anonymous
You said my example was passing by value.
Yes. And I have used your example in my post to explain why.
Talula
Yes. And I have used your example in my post to explain why.
And you read it then... and understand it is not passing by value, it is totally a different thing.
Pavel
This is pass by value and not pass by reference
I think you've started with this, right? We had a similar discussion with you and I remember that there was a problem with using different vocabulary. Basically, pointer to int is passed by value, that is true (but that is probably not what Tazz was talking about). int there is not passed by value, neither by reference. So it seems that you are arguing about different things
Pavel
As we were the last time
Talula
I have nothing against you but if you keep arguing without reading other posts, it just pisses off people.
#include <iostream> void foo(int y) { std::cout << "y = " << y << '\n'; } int main() { foo(5); // first call int x{ 6 }; foo(x); // second call foo(x+1); // third call return 0; } This is example of passing by value.
Kevin
my mind blown away
Anonymous
I think you've started with this, right? We had a similar discussion with you and I remember that there was a problem with using different vocabulary. Basically, pointer to int is passed by value, that is true (but that is probably not what Tazz was talking about). int there is not passed by value, neither by reference. So it seems that you are arguing about different things
Pass by value and pass by reference semantics is with respect to the paramater. It doesn't matter if the parameter is a pointer. Unless the parameter is a reference type, pass by reference semantics is not used. For pointers,people generally use pass by pointers to describe that they are talking about the pointed to value because passing by pointers is also pass by value.
Anonymous
What do you consider reference, what do you think that is for? Reference of what? Memory location... that is it.
Yes. References are implemented underneath using const pointers too. But that doesn't change the fact that "pass by reference" is used only for reference arguments in C++ and not for parameters of other types
Pavel
It doesn't matter what she is talking about. The point is that "pass by reference semantics" is wrong in her use case
Well, if you don't want to understand what your opponent is trying to say, then you will not get to a reasonable conclusion in the discussion
Kevin
i guess i was learning bad
Talula
Yes. References are implemented underneath using const pointers too. But that doesn't change the fact that "pass by reference" is used only for reference arguments in C++ and not for parameters of other types
So passing a variable by pointer is not passing the variable by value... it is "in technical" terms passing by "pointer" but not by value.
Anonymous
Well, if you don't want to understand what your opponent is trying to say, then you will not get to a reasonable conclusion in the discussion
I understand what she is saying and saying she is using the wrong term for it. Pass by reference has a different meaning in the C++ community. You can't change the meaning to suit your needs
Talula
I understand what she is saying and saying she is using the wrong term for it. Pass by reference has a different meaning in the C++ community. You can't change the meaning to suit your needs
Maybe... but that doesn't make me stupid... Reference means memory location and pointer passes exactly just that memory location.
Anonymous
So passing a variable by pointer is not passing the variable by value... it is "in technical" terms passing by "pointer" but not by value.
But the pointer is passed by value. Of you look at it from the function's perspective, it exhibits pass by value semantics. If you want to lay emphasis on the pointed to value, you have to use the term "pass by pointer" and not "pass by reference" in C++.
Talula
But the pointer is passed by value. Of you look at it from the function's perspective, it exhibits pass by value semantics. If you want to lay emphasis on the pointed to value, you have to use the term "pass by pointer" and not "pass by reference" in C++.
Everything is in reality is passed by value... there is no such thing as passing something without passing values. Reference is reference to the location where the information is stored and point is pointing to the memory area where information is stored... But value is only the value of that variable whatever it is at the time it is passed.
Talula
Can we say pass by address also?
Address is the same exact thing... reference, pointer, address... on the other hand value is a different thing, where value of the variable is passed.
Kevin
so, how can i start my code? haha
Anonymous
so, how can i start my code? haha
reading the references :)
Talula
No reference is different and so is pointer
Explain me how... please... tell me what it does differently when you pass reference or pointer... And I accepted before that I'm not good with terminologies... I'm not in college. But when you say I want to pass a variable which is actually a pointer to memory location X or you want to specify in the function itself that it should give you address or memory location of the variable in memory... It is technically same thing.
Kevin
hahaha
Kevin
reading the references :)
im reading what you sent
Anonymous
Everything is in reality is passed by value... there is no such thing as passing something without passing values. Reference is reference to the location where the information is stored and point is pointing to the memory area where information is stored... But value is only the value of that variable whatever it is at the time it is passed.
NO THIS IS WRONG. In C++ standard, references are not objects but aliases. So if you have a function which takes a reference arguments, you are not passing anything by value. The function has an alias for the original argument. In C++, you can't have pointers to references because technically they are not objects. SO ONCE AGAIN YOU ARE WRONG.
Pavel
I understand what she is saying and saying she is using the wrong term for it. Pass by reference has a different meaning in the C++ community. You can't change the meaning to suit your needs
I don't think you do. The example was incorrect, but you pointed out an unrelated thing (maybe technically correct, but does it matter), and then you started arguing about different things
Anonymous
im reading what you sent
well, that's all, nothing too complicated
Anonymous
I don't think you do. The example was incorrect, but you pointed out an unrelated thing (maybe technically correct, but does it matter), and then you started arguing about different things
I am not arguing about different things. The question was about pass by reference and the example she gave was pass by pointer which is wrong and which is what I pointed out. I also said that even her case is also pass by value which is also correct.
Talula
Either you can pass the value or memory address of the place where information is stored... what is that 3rd thing.
Anonymous
You think anything other than memory address is passed? If you think so tell me what is passed...
It doesn't matter how it is implemented underneath. The standard says that references are aliases and are not treated as objects. You can have a pointer to a pointer but you can't have a pointer to a refernce even though references are also implemented as a pointer. So references are not equal to pointers. The standard has the last word.
Kevin
First time writing here, and i create a plot.
Pavel
I am not arguing about different things. The question was about pass by reference and the example she gave was pass by pointer which is wrong and which is what I pointed out. I also said that even her case is also pass by value which is also correct.
Yes it is "pass by pointer", but you started talking about "pass by value" which is confusing because a minute ago you were talking about int but suddenly you started talking about pointer to int without mentioning that explicitly
Anonymous
So I'm stupid... right? And in any case it is not pass by value.
So the standard is wrong to clearly mention that references are aliases and pass by reference is meant to the refer to those cases where the parameter is a reference. So clearly you know better than the standard
Anonymous
Talula
So the standard is wrong to clearly mention that references are aliases and pass by reference is meant to the refer to those cases where the parameter is a reference. So clearly you know better than the standard
I am not talking about standard... maybe you're right I have already said it before I'm not good with terminologies. But they work exactly the same way and it is not passing by value. And I didn't enjoy being called "Stupid".
Talula
Am asking again can we call it pass by address 😃
In my book you can call it anything... it is simply not passed by value... Either the variables can be passed with address or passed by value...
Anonymous
In my book you can call it anything... it is simply not passed by value... Either the variables can be passed with address or passed by value...
It is unfortunate if you pass off statements from your imaginary book in a community where there are other books which hold a higher value and which have clearly defined what pass by reference is and what pass by reference semantics is.
Talula
Can you please not ask unrelated question?
Pavel
Just because you end up getting confused doesn't mean I am wrong. There were quite a few guys who agreed with me there. They didn't all get confused like you
Well, that's not a valid point. I mean you had already two arguments with two different people on the same topic for basically the same reason, and still you say that these people are wrong because they didn't understand how you think
Anonymous
When you don't even know what is passing variable by value, nice.
I know it and the standard does and we know the effects. The fact is that you don't.
Talula
What is a reference, first understand that... it is nothing but pointer to the memory location of the object, variable...
Talula
Not a pointer but an alias
Yeah, what is an alias? Something different other than memory area?
Anonymous
What is a reference, first understand that... it is nothing but pointer to the memory location of the object, variable...
REFERENCE IN C++ is an alias according to the standard. There are two types - lvalue and rvalue references It is a compound type that is different from pointers. The standard does not mention anything about how they are implemented. So please don't argue here without knowing about them in detail.
Anonymous
Yeah, what is an alias? Something different other than memory area?
It can be whatever. It can be implemented using pointers. I posted a link to the standard document. So there is nothing to argue here except perhaps to pass off your ignorance.
Anonymous
It cannot be whatever... learn how computers work.
Lol. Someone is arguing against the standards and asking me to learn about computers. Did you read the message again? I POSETED A LINK TO THE C++ STANDARD. THE PASS BY REFERENCE SEMANTICS is explained clearly. So this is your final warning.
Anonymous
Saying the correct thing from the standard is different from saying something that contradicts the standard
Anonymous
You think anything other than memory address is passed? If you think so tell me what is passed...
https://stackoverflow.com/questions/4426474/is-passing-pointer-argument-pass-by-value-in-c Since you can't understand the standard, here is a Stackoverflow link
Anonymous
Did you read "as anything else"?
What is "as anything else"? The question was "is passing a pointer pass by value in C++" And the answer was YES.
Talula
What is "as anything else"? The question was "is passing a pointer pass by value in C++" And the answer was YES.
So what is a reference, something special other than pointer to the location? I would like you understand how things work rather than just saying "This is what the book says".
Anonymous
So what is a reference, something special other than pointer to the location? I would like you understand how things work rather than just saying "This is what the book says".
References are pointers in most implementations. But they have a special syntax different from how you use pointers which is what makes them different. The phrases "pass by value" and "pass by reference" are used to highlight these differences
Anonymous
you can always contact him https://rocketreach.co/bjarne-stroustrup-email_754251
Talula
References are pointers in most implementations. But they have a special syntax different from how you use pointers which is what makes them different. The phrases "pass by value" and "pass by reference" are used to highlight these differences
That makes no clear statement at all... See when a function is called, there are 2 ways to send information to the function. 1. Putting the value on the stack 2. Putting the address or memory location of the variable on the stack. When the function gets the control, it pop these numbers and it knows what are these... What is reference, if it is not one of these two things.
Talula
Well, in C++ it doesn't matter how it's implemented, it matters how it's described in the standard.
Maybe... But passing information as a pointer is not by value but by reference to the location in memory which holds the value.