#include void swap(std::string &x, std::string &y); int main() { std::string x = "Kool-Aid"; std::string y = "Water"; swap(x, y); std::cout
@RandomCommentator1524 күн бұрын
@@farisvaljevac1478 Yeah this function exists but he is trying to teach about reference and eventually how the built-in swap(x,y) function works under the hood to the beginners. :)
@ganapathipasupathi16665 ай бұрын
many thanks sir, my many confusions are cleared. I have been watching this series from one week before, Sir did the 👏🙌good job
@Clockwerk777 Жыл бұрын
So if i understand this correctly, is this the same concept of variable scope? where basically when you pass by value you get local versions of X and Y, which is what the function swaps, rather than the main()value?
@lastwaveundergroundsaviour70372 жыл бұрын
i have been trying to do this, now i realize after watching this video that i was doing it backwards. ahaha thanks man
@FrederikWollert6 ай бұрын
Nice Video. But should also say that pass-by-value/reference means the same as call-by-value/reference.
@renusoni60775 ай бұрын
Is it a good practice to always pass variables by reference to the functions?
@shervin956110 ай бұрын
Thanks a lot!
@adnanaman4391Ай бұрын
We are passing Memory Addresses from the main function to the made up Swap func through param &x&y , swapping activity done inside the swap function....then it goes on to display changed vals
@user-dy1vf7lu3i Жыл бұрын
1:58 Why don’t we just return X and Y? Void function don’t have return types so we change the “void” to a “string” right? Or is there no such thing as a string function?
@aliceylan1211 Жыл бұрын
You could but the point of the video is to demonstrate the difference between passing by reference and passing by value
@ishaqmangansakan7574 Жыл бұрын
There is a string function, but it just happens to prefer to use a void function.
@garyalvarado21553 ай бұрын
if this is the case shouldnt we always pass parameters by reference?
@kristijanlazarev8 ай бұрын
I see mine are swapping even without passing by reference, why
@SafwanMashrafiSaraf-ll1wlАй бұрын
could you post the code here
@lastwaveundergroundsaviour70372 жыл бұрын
oooo interesting
@user-lyf4isnt7daijobu4 ай бұрын
#include void _swap(std::string x, std::string y); // passing by value // does not change value in place due to varying scopes(different memory addresses) void swap(std::string &x, std::string &y); // passing by reference // "reference" to memory address so that it changes in place int main() { std::string x = "Kool-Aid"; std::string y = "Water"; _swap(x,y); std::cout