Buckys C++ Programming Tutorials - 39 - Pass by Reference with Pointers

  Рет қаралды 649,741

thenewboston

thenewboston

Күн бұрын

Пікірлер: 590
@antiHUMANDesigns
@antiHUMANDesigns 9 жыл бұрын
This is a bit wrong. Pass by reference uses references, not pointers. Pass by *address* uses pointers. Reference and address is not the same thing. It's an important distinction because pass by reference is handled differently when calling the function. Pass by reference function looks like this: passByReference(int &x); // reference, *not* pointer. While pass by *address* looks like this: passByAddress(int *x); // pointer The important difference here is that passByReference is used (called) the same way as passByValue, while a passByAddress requires that you specify an address or a pointer as the argument. That is, you need to send a pointer/address, or you need to put an ampersand (&) in front of your variable to denote it's address rather than it's value.
@GreenPlimpie
@GreenPlimpie 9 жыл бұрын
antiHUMANDesigns Thank you! I was starting to doubt myself there when I couldn't find any comments pointing out the mistakes here. He got reference and address completely confused and he's probably gonna confuse lots of people :/
@antiHUMANDesigns
@antiHUMANDesigns 9 жыл бұрын
Randa Moustafa Yeah, it's a shame.
@antiHUMANDesigns
@antiHUMANDesigns 9 жыл бұрын
Kim Nguyen Yes, a reference is an alias. Change the value of the alias/reference, and you change the original value aswell, because they're the same thing. References simply allow you to extend the scope of something, instead of having to copy it. As for "swapping" references, you can't, but you can still swap "by value". If you send x and y by reference into a "swap" function, the funtion will store x in a temporary variable, then copy y to x and then copy the temp to y. So it's a swap by value. If you send a "reference to a pointer" into a function, then you can swap the pointers without having to copy the data the pointers are pointing to. Just swap the addresses instead. Not sure you understand the concept of "pointer-to-pointer" or "reference-to-pointer". Tell me if it doesn't makes sense to you. I hope I understood your question correctly.
@mishoaleksidze7820
@mishoaleksidze7820 9 жыл бұрын
+antiHUMANDesigns Thanks for writing this comments, now it's clear...
@antiHUMANDesigns
@antiHUMANDesigns 9 жыл бұрын
***** A reference is just an alias. Say you create an object or variable and call it "a". Then you create a reference to that object or variable, and the same object/variable simply has 2 different names. Lets say the reference is called "b". So no matter if you use "a" or "b" it will be exactly the same thing. int a; int &b = a; // reference to "a" Now, in every way, "a" is the *same* as "b", and they can be used the exact same way with the exact same result. They are the same. A pointer, however, is different because once you've used it to point to something, you can change so that it points to something else, and you can also change it so that it points to *nothing*. References can never change what they refer to, once they've been created, and must always refer to something. And pointers use different semantics, so they kind of "look" more different than they are, in a sense. So what's the point of references? They allow you to extend the scope of something, that's their one and only purpose, unless oy usimply use them as aliases, whcih is kind of pointless. This means that when a variable would normally not be in a specific scope, you can make it be in that scope by using a reference. For example: int a; myFunction(a); Inside that function, "a" doesn't exist, it's not its scope. But sending a reference to the function extends the scope of "a" so that it also exists inside the function. And a function that returns a reference allows you to extend the scope of a temporary variable/object from inside the function, so that it remains outside of the function, where it would normally be automatically deleted. int& myfunction() { int a; return a; } Even though "int a" is a temporary variable that would be automatically deleted when the function ends, because a reference to it is returned by the function, it won't be autoamtically deleted. So it's scope has been extended to the scope where the function was called. Some people may tell you that you can't do that, but you can. Perhaps you couldn't do it in some older version of C++, I don't know.
@Seannyoo900
@Seannyoo900 8 жыл бұрын
It's funny how my professor tried to describe how this works in a 2 hour lecture to no avail, and I got it immediately from your videos in about 20 minutes. Good job man :) thank you.
@geekybench
@geekybench 7 жыл бұрын
Mine has been teacher for almost a semester
@jayblankenship1553
@jayblankenship1553 6 жыл бұрын
thats how professors are they are more focused on sounding better then you while this guy cuts the shit and tells it to you straight.
@darrenfrancis8126
@darrenfrancis8126 Жыл бұрын
for me this is better because i can stop on the section I'm confused about and until i understand ill move on. My professor is face paced but I use her as an outline of what's important to study since i can't sit there and ask questions about everything during the lecture.
@advaitharmy
@advaitharmy 8 жыл бұрын
For people who are having confusion over *x = 66. Let me explain, When a value is assigned to *x in any places other than pointer declaration place(i.e int *x), it is called as dereferencing the pointer. In simple words what *x=66 does is assign a value of 66 at the address pointed by the pointer.
@gowthamprabhu122
@gowthamprabhu122 7 жыл бұрын
oh that makes it much clear. But what about the declaration place? To make x point to sandy do we declare int *x= sandy or int *x= &sandy ?
@advaitharmy
@advaitharmy 7 жыл бұрын
It depends on what sandy is here. Sandy should be a integer value here, as x is a pointer of type integer. So int*x =&sandy is correct where x has address of sandy. If sandy is an array of characters you can just write string*x = sandy, where & is not required while assigning the array address.
@nickbossbg5636
@nickbossbg5636 7 жыл бұрын
Here i will try to explain: Dereferencing a pointer means to get the value of the address to which the pointer is pointing. int betty = 13; // defining a variable called betty with value 13 int *x; // declaring a pointer x, here int *x means that we are declaring int pointer with name x x = &betty; // here we are making our pointer x to points to the memory address of the variable betty *x = 66; // here we are dereferencing the pointer and assigning value 66 at the address to which our pointer x is pointing cout
@Happydayz-2025
@Happydayz-2025 6 жыл бұрын
NickBossBG In the pass by reference function, instead of passing a copy of the value contained in that variable, the programmer passes the address of the variable which allows the user access to modify the value at that address.
@warkid999
@warkid999 6 жыл бұрын
this cleared all my doubt thanks buddy
@skippyscourge181
@skippyscourge181 12 жыл бұрын
Bucky, just wanted to say, you are an extremely good teacher, i was having a hard time grasping classes and pointers in c++ until you put them into plain simple english, I'm kinda new to c++, but I've been programming in various other languages since the late 80s, and never have i seen or experienced such amazing teaching.
@jake2663
@jake2663 5 жыл бұрын
These tutorials are from 2011 over 7 years old and they are still so very helpful bucky I know you probably don't read comments anymore but thank you so much you've helped me through so much and taught me so much and not just helping me with my C++ homework.
@georgekougioumtzoglou5344
@georgekougioumtzoglou5344 7 жыл бұрын
I love your tutorials... I am sitting and watching them although I know C++!!! I think you are a have a great talent in teaching.
@TheeChrist-Talks
@TheeChrist-Talks 3 жыл бұрын
This is awesome
@good-tn9sr
@good-tn9sr 3 жыл бұрын
@@TheeChrist-Talks woowowwowowowoow very cool
@reefsami8010
@reefsami8010 6 жыл бұрын
So that’s my second semester in programming.. and still when ever I get stuck in some things and I can’t figure them out I immediately think “ oh I think I need to go on KZbin and see what bucky said about it” then I understand it instantly.. you have an incredible and effective way of delivering information .. you have a gift man .. Arab people love you 💚💚💚💚
@PravatKTimsina
@PravatKTimsina 3 жыл бұрын
I don't know how far did you reach by now. You commented three years ago. I'd be more than happy if you could share your experience. I am a beginner it can be a motivation. 4/29/2021
@laqras
@laqras 2 жыл бұрын
@@PravatKTimsina what happend now? are you now good i coding?
@strangecuriousandunusual
@strangecuriousandunusual 7 жыл бұрын
#include #include #include #include #include using namespace std; void passByValue(int x); void passByReference(int &x); void passByAddress(int *x); int main(){ int salley = 11; int betty = 12; int ella = 13; cout
@ouihui
@ouihui 6 жыл бұрын
Thanks for this example! Quick question, when you pass by value, how do we get the value 99 to be returned (besides using pbr or pba) so that we can cout 99 instead of 11?
@alexandrucosmin90
@alexandrucosmin90 6 жыл бұрын
can you explain me how they are conected? X -> int bella, then X -> int betty X -> int Ella? please!
@gamepurpose
@gamepurpose 6 жыл бұрын
so what is the different between the 2nd and the 3rd example? any benefit doing one not the other?
@GTBBwastaken
@GTBBwastaken 5 жыл бұрын
​@@ouihui Excuse me for being 1 year late, lol. I will use part of the above example to help you: int passByValue(int x){ x = 99; return x; } in main you need to cout
@jorgehabib8661
@jorgehabib8661 5 жыл бұрын
fire
@Bugazia
@Bugazia 10 жыл бұрын
reviewing C++ as i havn't been around it for around 11 months or so, and you're making it easier for me, thanks Bucky!
@GuyBaker555
@GuyBaker555 10 жыл бұрын
Very good Bucky, I am retraining from C to C++ so a lot I can skip through but the explanations of C++ specific features, in small easy to digest steps is fantastic!
@AlexTimification
@AlexTimification 11 жыл бұрын
Thanks Bucky, for your tutorials. I'm learning c++ after java and c#. As a Java-programmer on an amateur level, I would say, the pointer feature is by far the most noticable advantage of c++ over java. And the passByReference feature is just amazing in C++. TO make it in Java, you need to write more code :D
@fusiondew
@fusiondew 5 жыл бұрын
I've been trying to learn OpenGL and I couldn't wrap my head around why you would go through the trouble of making a pointer and passing that instead of just the variable but it makes perfect sense now. Thank you bro!
@JRichard112
@JRichard112 7 жыл бұрын
Know this was sometime ago, Bucky, but this was really comprehensive. Learned a lot from it.
@RobertGuilman
@RobertGuilman 3 жыл бұрын
Thankkkkkk yoooooooouuuuuuu, i really struggled with this. Your explanation is the clearest even tough it was made 9 years ago
@kkkkkkkkkk191
@kkkkkkkkkk191 13 жыл бұрын
Passing by reference can also be done by not using pointers, in that case we pass the variables in our function as: void passByReference(int &x){ x=66; } this would actually set the value of the variable passed as 66. now when we call it in our main function : ... void passByReference(int &x); int main(){ int a=10; // any variable a passByReference(a); // here we passed the variable 'a' and not the pointer a cout
@BuckFangs
@BuckFangs 9 жыл бұрын
Thank you bucky, extremely grateful for the tutorials and the fact that they are quick lessons.
@EnterANameReal
@EnterANameReal 13 жыл бұрын
@chiste916 I think some comments before answered this. Normal passing by reference uses the ampersand(&). But this is pass by reference WITH pointers. So if you pass a pointer, you have to dereference it with the asterisk (*). A pointer contains a memory address, you derefence the memory address to access the data it's pointing to.
@juzzy1k
@juzzy1k 11 жыл бұрын
dude you are so helpful. this is so much better and helpful then my class im taking!
@seto713
@seto713 9 жыл бұрын
I swear, you're truly a genius. I go to lectures staring at my Professor for three hours as he goes on and on about this shit and you cleared it all up in less than 10 minutes. Thanks :D
@kkkkkkkkkk191
@kkkkkkkkkk191 13 жыл бұрын
the reason, why the code below works is that when we use pointer (which is actually the address of variable , i.e. *pointerA=&a; (here 'a' is any variable).) the parameters of the function is an address, so while calling it we need to pass an address, this is what Bucky did in the tutorial. similarly when we use '&', the parameter(s) is an address [just like the case in pointers] but while calling the function we do not have to pass the pointer of the variable, we just pass the variable itself
@sidrockx95
@sidrockx95 11 жыл бұрын
the best part is : he makes those videos in under 8 minutes. most of 'em. And its so easy to grasp all the things he says. exceptional teaching! :)
@shizyninjarocks
@shizyninjarocks 8 жыл бұрын
Super cool! Thx, Bucky, you've saved my ass so many times.
@HugoIetsGaming
@HugoIetsGaming 9 жыл бұрын
I am beginning to understand pointers, Bucky you are a hero!
@kaibest
@kaibest 4 жыл бұрын
so many years... and now i understood. thanks so much man!
@tejaskadam1889
@tejaskadam1889 6 жыл бұрын
sorry to say that but here you made mistake in interepretation if this is the case that we should call it as pass by reference,then what is the case for pass by adress using pointers,here you have shown pass by adress using pointers;
@joshp3446
@joshp3446 6 жыл бұрын
honest to God over the past few days i have scoured the internet i have searched what feels like Dozens of Articles, Videos, Forums, Etc. and only about 2 or 3 People that i found (And i had to DIG for these videos btw) only like 2 or 3 of you explain THE CRUCIAL DETAIL THAT POINTERS (AND NOT JUST DE-REFERENCEING A POINTER, TO PULL THE VALUE OUT) STORE THE VALUE OF THE MEMORY ADDRESS AND THAT IT CAN BE CHANGED, ITS NOT JUST THE ADDRESS THAT GETS STORED THE VALUE TOO! NO ONE BOTHERS TO EXPLAIN THIS DETAIL! AND YOU DID! THANK YOU! I UNDERSTAND THIS SO MUCH F*CKING MORE NOW BECAUSE YOU ARE ACTUALLY INTELLIGENT! THANK YOU SO MUCH, YOU HAVE EXCELLENT VIDEOS, AND YOU HAVE EARNED YOURSELF A SUBSCRIBER. THANKS AGAIN!
@linkinaryan
@linkinaryan 7 жыл бұрын
Bucky: (types) int betty = 13; int sandy = 13; Me: *sigh* i see..bucky u still haven't gotten over ur break-ups....
@silakanveli
@silakanveli 6 жыл бұрын
Thanks for this video. Probably the best video about why to use pointers. Bravo
@TheHTMLCode
@TheHTMLCode 12 жыл бұрын
yes - when you think about it - passByValue(betty); has a value of 13 so the output would be 13, int x is not called because it is not required to, as value Betty is the input value. in the case of sandy = 13, she is obviosly reset to the value of 66 because passByReference(&sandy); assigns her with the pointers memory value = 66 Hope this makes sense :)
@Phoenix700
@Phoenix700 11 жыл бұрын
Man you explain these topics sooo much better than my uni textbook, in 8 minutes I understand pointers compared to weeks being confused by it
@ElderGod4
@ElderGod4 11 жыл бұрын
There's a diff between coders and programers :P
@MrFavorite01
@MrFavorite01 11 жыл бұрын
***** Sorry, I'm a bit dimwitted to what you said. Can you tell me the difference? I'm can only guess by what you mean.
@dibbiepk
@dibbiepk 10 жыл бұрын
Sun E. Coders, are people who can understand the code, and write code, but dont exactly have any idea on what there doing. There advanced in logically THINKING and UNDERSTANDING, then ACTION, and PHYSICAL CONSTRUCTION. Programmers are people who can write code, debug (test and edit, and remove errors and idiot-proof it) code. They have a general understanding on the code,they know what all the functions are at least, but they also have a idea on what their doing, and why they did it. They can explain it, and remake it if needed. And they can (normally) do it in many different ways, or at least know many different ways it can also be done. Bucky is a programmer. He is experienced. When he was starting out learning to program, he might be considered a coder. He was not experienced. He may of understood what a function did. But had no idea how to re-produce the function. In any programming production, a coder may be just as useful as a programmer. If that makes sense... If not, check this out: workfunc.com/differences-between-programmers-and-coders/ Might explain it better.
@kkkkkkkkkk191
@kkkkkkkkkk191 13 жыл бұрын
[contd. from my last post] because you have '&' which explicitly refers to the address of the variable. Also in this case we do not need to use the dereference operator * , in order to alter the value of the variable passed. i.e. instead of *x=66, we can do x=66. Hence it means the same thing. Just a slight change in concept.
@FatMorton
@FatMorton 6 жыл бұрын
A good way to remember this is by imagining that the argument is changed to int x = betty, meaning that if you change x, it will not change betty. By saying int* x = &sandy, you are saying that x is pointing to where the original sandy is stored, allowing you to change sandy by changing the contents of where x is pointing to. If you don't get it, look below. since in _"passByValue(int x)"_ "x" is a normal variable, _"passByValue(betty)"_ is like saying _"(int x = betty)"_ so f you change x, it won't change betty. but since in _"passByReference(int* x)"_ "x" is a pointer, _"passByReference(sandy)"_ is like saying _"(int* x = &sandy)"_ so if you change *x (the contents of x), it will change the value of sandy.
@dmaster20ify
@dmaster20ify 7 жыл бұрын
Thanks man. Thanks to your videos, Only now do I really understand what a pointers. Metaphorically, a pointer is like a parasite. It doesn't own any address in memory and has to leech onto another variable of the same type. You don't use the * pointer operator when you want to change the address of the pointer. But you use the * pointer operator to change the value stored at the address and also to declared the pointer in the first place. A very important rule is you cannot assign a value to the pointer variable when it is newly created. This is because as I said; the pointer variable is a parasite because it isn't born with a memory address. Or to put it another way, the pointer variable is a homeless man! Since it isn't given a place in memory, it simple cannot store any value in memory. Memory is where all the values of your compiled program is stored until you programmed it to write the values to your harddrive. So the pointer is born without any address and cannot store any value. But once you point the pointer to the address of a variable, it basically hijacks the address of the variable. Now it is able to store values. When storing values to the pointer variable's name, you must include the * pointer operator. Only one value can be stored to any address in memory, so giving the pointer variable a value will simultaneously change the value of the original variable. Reversely, changing the value of the original variable also changes the value of the pointer variable. Funnily, the pointer variable can decide to stop being a pest to one variable, but then it has to be a pest to another variable. To change the address of a pointer variable you say pointer variable = address of next variable. Just ensure that you don't use the *pointer operator. In fact I really think that sign means "value of pointer". Check out the following example for a better illustration. You can also compile this program, because I tediously checked it for errors, run it and you will get a very good illustration of how the pointer works in C++. _______________________________________________________________________________ #include using namespace std; // using std namespace is cool because my code is short /// Declare Global Variables int a = 10; int b = 20; int *pnt; // saying "*pnt = 100" is big mistake because "pnt" has no address now /// Main Function int main () { { cout
@ujjwalmainali3927
@ujjwalmainali3927 10 жыл бұрын
don't know why but i learn fast with your explanation. Thank u Bucky.
@shinemooon
@shinemooon 12 жыл бұрын
I love you Bucky. I hate pointers before, but now, thanks to you, I understand them very clear.
@lukecharles3880
@lukecharles3880 5 жыл бұрын
"i mean come on guys, enough with the E's." Had me in stitches xD
@lloydydydy
@lloydydydy 11 жыл бұрын
You're the only one who made me understand the reason to use pointers. Thank You!
@w0mblemania
@w0mblemania 13 жыл бұрын
@Anddosdd Because it's much more important at this stage to show people how pointers work. C++ References tend to obscure and confuse the role of pointers for newbies. Only once programmers fully understand pointers, can can use References properly, including knowing when not to use them.
@Rigardoful
@Rigardoful 13 жыл бұрын
@uccoskun He'll probably explain later on ... Arrays are pointers. When you create it, it allocates enough memory for n elements. Every element takes a k number of bytes, which your pc knows and they're all in one block of memory, the one after the other. So supposing the address is number M, to access element 5 it says, I'll go to address M+5*k. So when passing an array, you're passing a pointer to the first position.(if not mistaken, array[] gives you a pointer to the block of memory) I
@zeMasterRuseman
@zeMasterRuseman 11 жыл бұрын
Best explanation of pointers I've seen. This pointer confusion was scaring me away from C++, now I might go and learn it.
@TheTurmAx
@TheTurmAx 11 жыл бұрын
You could also pass reference like: int main() { int x = 0; modValue(x); cout
@Pwncakes1966
@Pwncakes1966 13 жыл бұрын
As soon as you explained that it gives functions direct access to a variable I saw about 1000 game programming uses. =D
@pietrocasalone8815
@pietrocasalone8815 6 жыл бұрын
like most people said, this is the very first not totally clear tutorial of c++ you did; the only mystake is that you didn't introduce the deference operator making us to panic. BTW one error in 38 tutorial doesn't make these tutorials less awesome
@thegamingruler1996
@thegamingruler1996 12 жыл бұрын
this is basically ByRef and ByVal in Visual Basic but now I understand how ByRef works from inside you learn so many neat things switching from high level language to a low level one :)
@CSryand2m
@CSryand2m 9 жыл бұрын
Passing by reference to C++ is like gravity is to Interstellar. Pass by reference (gravity) is a way of communicating with the heap (the past), by transcending the dimensions of the computer (space time) in which it was previously bounded by the call-stack (the present). Nerds unite!
@kaoknight
@kaoknight 12 жыл бұрын
Thanks you for the tutorials. You are way better than all of my professors.
@UAslak
@UAslak 10 жыл бұрын
This is amazing. I had a C course that introduced pointers as something difficult and dangerous, but I literally understood it the first time you explained it. One question though. You said something like, it's useful to give functions direct access to variables so the computer doesn't have to make a million copies of that variable. Does that mean that it is common practise ALWAYS (or in most cases) to give functions direct access in order to save computing power?
@Kyle-ob7us
@Kyle-ob7us 10 жыл бұрын
I would think that this would only make a difference if you were working with some large amounts of data, or if the value had to change permanently (although you could also give it a return and set it equal to that)
@bayleymakloski532
@bayleymakloski532 6 жыл бұрын
If you know for a fact that you're going to need the original copy of that variable at some other point along the line, don't pass by reference. You'll end up using more of the memory of the computer, but if you are dealing with a small amount of data, even say 1,000 entries, you'll probably be fine. In practice, the more concise your variables are the better.
@hoxdl2131
@hoxdl2131 10 жыл бұрын
Hey btw, you are not passing by reference, you are passing by pointer ( just something to keep in mind).
@nayanparmar9871
@nayanparmar9871 4 жыл бұрын
Just check again the whole code and watch again the whole video. In video we are passing by reference with pointers you know so it's correct . Passing by reference with pointers na that's why you seems like that
@Nick-lx4fo
@Nick-lx4fo 4 жыл бұрын
@@nayanparmar9871 Technically it's not a reference, he's passing a value using a pointer, a pointer is not a reference, a reference is denoted by an &. He'd want to be using that instead of pointers favorably.
@PeterLakeTV
@PeterLakeTV 12 жыл бұрын
Bucky, you have such a magical way of making anyone understand things. We all can't thank you enough for your awesome free educational videos. I swear, you should move to Canada and be my teacher :P
@toxickremedy
@toxickremedy 10 жыл бұрын
Thnx a lot. This was very clear. It took me 4 times to watch to understand it, but this was great.
@hariscengic7302
@hariscengic7302 7 жыл бұрын
I laughed my ass off at the end "Aaaanyways, moving on " hahahahah .... i wanted to hear the milkshake story
@PrasannDatta
@PrasannDatta 12 жыл бұрын
thanks bucky you saved me from failing in exam , you are just amazing buddy GOD BLESS YOU
@Fireblades212
@Fireblades212 12 жыл бұрын
im just goin out on a whim here, but i beleive you learned more from bucky because your not limited in how fast you can learn.
@metax73
@metax73 11 жыл бұрын
YES, I will dream of this tonight. Complete Bliss.
@ubuntujax5008
@ubuntujax5008 10 жыл бұрын
dude i love your c++ tutorials. You crack me up and help me learn!
@18vallancel
@18vallancel 11 жыл бұрын
In all my CompSci classes my lectuerer never once touched a computer- 100% death by powerpoint. Surprisingly I didn't learn anything. But you, Bucky, are something else :D
@d_disjointed_d
@d_disjointed_d 12 жыл бұрын
Man, thank you very much! Only because of you and your tutorials I'm finally understand what pointers about! You are more than just awesome, you are incredible person and teacher! Sorry for bad English.
@decall
@decall 6 жыл бұрын
I have watched your video 4 times and now I finally got it :) thank you..
@DJ11726
@DJ11726 11 жыл бұрын
That stills creates another variable, the value of which is set to betty. It still changes betty but the whole point is to use less memory so your programs don't bog computers down with a bunch of variables that really aren't needed.
@austinkarunyaaccount9907
@austinkarunyaaccount9907 6 жыл бұрын
I missed watching your tutorials Bucky :)
@asm3282
@asm3282 6 жыл бұрын
@6:55 "x" is a variable with the same "type" as "Betty" not "value". "Betty" and "x" have the same type of "int" but different value of 13 and 99 respectively.
@bayleymakloski532
@bayleymakloski532 6 жыл бұрын
If you're watching today, this is not actually pass by reference, this is instead pass by address (pointer). To pass by reference, just simply put the '&' operator before your parameter. Then in the body of your function you can simply use the variable without having to put a '*' before the variable.
@leafmountain
@leafmountain 8 жыл бұрын
Finally I understand WHY pointers are used! Thank you!
@JakobRobert00
@JakobRobert00 12 жыл бұрын
your tutorials are very helpful you exlain everything very well
@cmcdonough2
@cmcdonough2 11 жыл бұрын
Seriously your vids have really taught me a lot. Thanks for taking the time to make them.
@kalanadesilva9425
@kalanadesilva9425 6 жыл бұрын
hey please do more videos your videos really help, way better than my professor's lectures. Thank you
@pip3s20
@pip3s20 10 жыл бұрын
First Thanks for this tutorial I'm learning c++ because I need understand some codes, I'm a Fortran Programmer and I do not understand what the pointer is....so, for example, we can do the same of passByReference() by doing this: int pass(int x){ x=66 return x; } and then in the main sandy=pass(sandy) Soy I need to know, when is recommendable to use pointers?? THANKS
@olestrohm
@olestrohm 10 жыл бұрын
the passByReference method puts less stress on your computer than the passByValue method or the method you made. hope you understand this :)
@tedmutesick5727
@tedmutesick5727 6 жыл бұрын
Now that's some Quality Tutorial and Teacher! Thankz Bucky!!!!
@SirRobbStarkGamin
@SirRobbStarkGamin 9 жыл бұрын
/* Example of Pass By Value and Pass By Reference, PBR is when the varible location and value is passed making it possible for a outside function to change the varible inside the int main, because PASS BY REFERENCE increases it's scope */ #include using namespace std; //This Function the value is passed an reference, where it can change the varible inside the int main void PassByReference(int& val){ val += 10; } //This Function ONLY the value is being passed, so the int main varible cannot be changed void PassByValue(int val){ val += 5; } int main(){ int num1 = 5; int num2 = 5; PassByReference(num1); PassByValue(num2); cout
@956Irvin
@956Irvin 3 жыл бұрын
You are a literal God send my friend. Thank you!!!
@skippycavanaugh3148
@skippycavanaugh3148 5 жыл бұрын
I ain’t gay, but I love u bro. My CS exam may go well because of ur short yet amazing videos.
@JPTeddy3
@JPTeddy3 10 жыл бұрын
Just to clarify in the third block code *x = 66 means you're dereferencing the pointer x and assigning 66 inside of the address?
@frankyu835
@frankyu835 10 жыл бұрын
yes it is
@ifyouwereasoup
@ifyouwereasoup 11 жыл бұрын
pretty sure that what you called passByReference is actually a passed by pointer function, since you had to dereference it and could go into arithmetics.. to be a passed by reference funtion you would use the actual int &x instead of the pointer to the adress inside the function.. this way you wouldnt have to dereference it too
@FamilyChannel7-37
@FamilyChannel7-37 7 жыл бұрын
keep it up. I love your presentation. My professor is using your tutorials in a class. You may update the tutorials from comments and suggestions. Again thanks a lot. Blessings!!!!
@longfeizhang4510
@longfeizhang4510 7 жыл бұрын
Thanks Bucky! I have benefited a lot from your videos.
@balanar4o
@balanar4o 6 жыл бұрын
excellent explanation. Thank you for helping me understand.
@Sunsetrider92
@Sunsetrider92 11 жыл бұрын
I finally fucking understand pointers. GAH, you're good, thank you.
@ahmermirza
@ahmermirza 8 жыл бұрын
Thank you so much!!!! I finally understand pass by value and pass by reference :))
@SandipGairhe
@SandipGairhe 6 жыл бұрын
I just came to know after all those above tutorial that you are genius. I know genius pretty well.
@ahmed45905
@ahmed45905 8 жыл бұрын
Thanks a lot for this great tutorial, however; I missed something and I couldn't figure it out myself. basically, I have 2 main questions. the first one actually is related to the passbyvalue function, if I changed the type of the function from void to int, will it change the output in the main method from 13 to 99 ??? the second question is: I watched another video that shows whenever i wanna include a parameter inside a function, like you did in the passbyreference, I shall be using (&) instead of (*). so is there any difference between * and &?? thanks in advance, You are doing great. Wish you best of luck.
@ahmed45905
@ahmed45905 8 жыл бұрын
+Peterolen already confused :D anyways, is there any reference i can refer to ?? taking into consideration i am just a beginner :)
@AhmedKhaled-wj7ds
@AhmedKhaled-wj7ds 7 жыл бұрын
in the passing by reference function why didn't we just type x=66; instead of using the pointer symbol (*x=66;) again, as i can see that we declared that it is a pointer in the function prototype.
@luissantiago7978
@luissantiago7978 7 жыл бұрын
"There are too many e's in reference" 😂😂
@quataoxann83
@quataoxann83 11 жыл бұрын
Reason why you use pass by reference is you can return more than one value. while for the pass by value, you can ONLY return ONE value at a time.
@josuegialis8146
@josuegialis8146 8 жыл бұрын
ayeee! lmao took a break from CIS homework to get a milkshake from McD's and came back to finish this tutorial lol
@goldse26
@goldse26 11 жыл бұрын
when you only need the value, say you have a function that calculates the area of something and you want the user to input the values, you don't need to change the original one's values, you only need to copy them to do something else
@kiva8986
@kiva8986 7 жыл бұрын
I usually do something like void changeValue(int &x){ x = 69; } So when I call the function, I don't need to type the ampersand. Is this wrong?
@iraqicode
@iraqicode 11 жыл бұрын
thanks for great tutorial but I have a qus. plz.. why is it useful to create such function like (betty) if we didn't change the value of x? any examples whats that function usful for?
@cameronaldridge5405
@cameronaldridge5405 6 жыл бұрын
Thank you I finally get the reason you’d use this
@guitarheroprince123
@guitarheroprince123 10 жыл бұрын
What you actually said is call by address and NOT call by reference.. People are really confused between reference and address.
@zeeshiscanning
@zeeshiscanning 12 жыл бұрын
youtube should have a button "like to the power of like" for bucky's videos :)
@starman5308
@starman5308 9 жыл бұрын
Sorry guys, I'm confused now. If passByValue doesn't actually change the variable, why do getter & setter functions work? Because when we use setTuna(int x) to set the value of "tuna" and then call getTuna() to get the value of "tuna", it returns the value modified. Isn't it contradictory? Or am I missing something here? If anyone could help me it would be great. Thanks!!
@dave369_
@dave369_ Жыл бұрын
A setter function is typically part of a class, that is changing a variable within the class's scope. The variable can be changed because the setter has access to it. But the PassByValue function here is just given a copy. The original is not in scope, the parameter is. Hence only the parameter is changed.
@forexsniper6061
@forexsniper6061 6 жыл бұрын
Thank you, very good explanation
@vibol03
@vibol03 12 жыл бұрын
a pointer to a pointer to a pointer to a pointer...and the circular list continues
@IronManhood
@IronManhood 6 жыл бұрын
func(int val)
@TJKhara
@TJKhara 6 жыл бұрын
Thank you! Your videos are awesome....
@dibbiepk
@dibbiepk 10 жыл бұрын
Are memory addressing assigned the same certain kind of characters? Like if you where to declare int fish = 10; in one program, then int fish = 10; in another program, would it be the exact same memory address? In other words: Like Binary, is the values for whatever the memory address is fixed?
@vidfellow
@vidfellow 10 жыл бұрын
no
@orzlar7928
@orzlar7928 10 жыл бұрын
the memory address is basically where it is stored in your RAM for instance, once the program closes, and re-opens the address will change.
@shivamdohare8294
@shivamdohare8294 8 жыл бұрын
sir y hav u used "*"x while assigning 66 when u hav already declared it as a pointer in the function passbyreference parameter
@donaldcsorny1487
@donaldcsorny1487 7 жыл бұрын
Bucky your a wizard! Another great tutorial.
@maxvandervoort3790
@maxvandervoort3790 6 жыл бұрын
So is it that the function passByReference gave Sandy's memory adress te value of pointer x and therefor Sandy equals 66?
@muratgenc2152
@muratgenc2152 3 жыл бұрын
Can I write x=66; instead of *x=66; in passByReference function? Is there any difference?
Buckys C++ Programming Tutorials - 40 - sizeof
6:08
thenewboston
Рет қаралды 344 М.
Buckys C++ Programming Tutorials - 35 - Passing Arrays to Functions
7:59
Sigma baby, you've conquered soap! 😲😮‍💨 LeoNata family #shorts
00:37
"كان عليّ أكل بقايا الطعام قبل هذا اليوم 🥹"
00:40
Holly Wolly Bow Arabic
Рет қаралды 15 МЛН
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 123 МЛН
Я сделала самое маленькое в мире мороженое!
00:43
Buckys C++ Programming Tutorials - 38 - Introduction to Pointers
6:07
Buckys C++ Programming Tutorials - 31 - Recursion
8:19
thenewboston
Рет қаралды 549 М.
Buckys C++ Programming Tutorials - 58 - function Templates
8:44
thenewboston
Рет қаралды 398 М.
Buckys C++ Programming Tutorials - 36 - Multidimensional Arrays
6:18
Buckys C++ Programming Tutorials - 60 - class Templates
9:58
thenewboston
Рет қаралды 384 М.
Buckys C++ Programming Tutorials - 53 - protected Members
8:21
thenewboston
Рет қаралды 263 М.
Buckys C++ Programming Tutorials - 52 - Inheritance
7:56
thenewboston
Рет қаралды 470 М.
Buckys C++ Programming Tutorials - 43 - Deconstructors
6:20
thenewboston
Рет қаралды 362 М.
Make Any Espresso Machine better than a $3500 one (With AI)
18:30
Chris Drake - That Automation Agency
Рет қаралды 375
Sigma baby, you've conquered soap! 😲😮‍💨 LeoNata family #shorts
00:37