C++ Tutorial 13: Passing by Reference vs Pointer

  Рет қаралды 49,373

Creel

Creel

Күн бұрын

Пікірлер: 73
@SmoothCode
@SmoothCode 4 жыл бұрын
No lie - this is the best video that explains how pointers work that I have watched on youtube so far.
@ColinJoe22
@ColinJoe22 9 жыл бұрын
I don't usually leave comments but you're a real Champ! Very easy to understand the difference between passing by value, pointer and reference. Cheers, mate!
@brianxavier8873
@brianxavier8873 Жыл бұрын
im finally saved. i wish i came across this video 8 years ago. i cant describe how difficult it was understanding such a simple topic. yours is the simplest and easiest explanation to yndwrstand. thank you very much
@sparrowthesissy2186
@sparrowthesissy2186 10 жыл бұрын
This video is perfectly clear, thank you. I've been getting through C++ with a bunch of different tutorials online, but this is the first straightforward explanation of pointers and references I've found. Thank you, again.
@oleksijm
@oleksijm 4 жыл бұрын
It's the accent, mate! Hehe. Great video too.
@anilkj7307
@anilkj7307 9 жыл бұрын
Best video on youtube. In my last 8 yrs career, I was not this much clear about PBR, PBP, PBV. Now I am feeling very much confident about these concepts.
@alfredcalleja450
@alfredcalleja450 7 жыл бұрын
Hi What's a Creel, I enjoyed your tutorial and got a lot out of it. I have read other explanations on how the Passing by Reference works and seen other videos, but yours is the best for explaining how the actual mechanism works. I like the way you get down to basics and explain the process from the ground up.
@MehmoodAhmedMooD
@MehmoodAhmedMooD 4 жыл бұрын
Man you've made my life much easier by explaining the usage of & symbol in pass by reference context. I was always confused by it's common use of specifying the address. Thanks a ton :)
@SuperYouVIN
@SuperYouVIN 12 жыл бұрын
You speak very clearly and straight forward. Good video.
@tava780
@tava780 10 жыл бұрын
Really enjoying your tutes! I'm not surprised at all that most of your videos have 0 dislikes. Thank you for your effort!
@bravheart95
@bravheart95 9 жыл бұрын
Best c++ tutorials on youtube !! Thanks alot
@manfredpseudowengorz
@manfredpseudowengorz 3 жыл бұрын
love those tiny bits of a fleeting confusion. they're the best. 16:16 So the two methods are exactly the same, they are pretty close, but they're not exaclty the same.
@BeefOffering
@BeefOffering 10 жыл бұрын
This was a great lecture, it cleared up a lot of confusion for me. Thank you!
@jealr2122
@jealr2122 9 жыл бұрын
Great video! Best explanation so far and good use of images.
@julianmahler2388
@julianmahler2388 6 жыл бұрын
6:07 Before I looked at your code, I tried to do the same thing by myself with a function plusOne(int* n) that takes a pointer to an int and increases the number by one. When I used *n++ in the function body, it didn't work and I got a warning "value computed is not used". When I changed it to *n+=1, it worked perfectly. Does anybody know why this is? Isn't n++ exactly the same as n+=1?
@roykimor
@roykimor 10 жыл бұрын
What's a Creel? 9:22 I'm pretty sure you meant to write points to an address 100 bytes higher (because it's a pointer to an int so 4 * 25)
@kcvinu
@kcvinu 5 жыл бұрын
Thanks for this video. Everything is crystal clear for even a newbie. Hope you can create more videos on the dark side of C++. :)
@d3duck
@d3duck 10 жыл бұрын
Such a good tutorial... Never really got this but this makes me wonder why not.. Thanks a lot
@Jack-4242
@Jack-4242 7 жыл бұрын
I think a good advantage of references is, that to the caller the function looks as if normal parameters are passed and the fact, that they are passed by reference is decided by the callee and kind of hidden on the caller side. for example, if we have a Matrix class and a function add, the caller expects that he can add two matrices with this function and he does not really care that they are actually passed by reference for reducing the overhead of copying. as well, if we read into variables by using std::cin, the variables are passed by reference as well, but it looks much cleaner and the caller does not have to think about passing by pointer as you have to when using scanf.
@cyndy3873
@cyndy3873 8 жыл бұрын
Thank you so much! I was so confused what the difference of passing by reference and passing by pointer was!!
@NickSuda
@NickSuda 9 жыл бұрын
Thanks for making this video dude, I finally fucking get it. I thought of a music production analogy: Passing by Value is like making a non-destructive edit to a track, at the expense of managing an undo list until you've saved. Whereas Passing by Pointer and Reference are like making destructive edits directly to a track. lol
@alexisp4157
@alexisp4157 10 жыл бұрын
Thanks for explaining this concept so simply. Really helped!
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
Great video sir. I look forward to watching your assembly with c++ vids next. Btw the "star" as you refer to it is called an asterisk. To each his own tho right?
@fmmjqtft1
@fmmjqtft1 10 жыл бұрын
7:00 onwards. I think the usage of the same name, "a" for the pointer in function Add25, and for the integer in main is confusing. Add25's "*a" is not the address of main's "a". Actually Add25's "a" is the address (or "pointer to") main's "a", and Add25's "*a" is the same thing as main's "a". So the upper blue box labelled "*a" should really be labelled either "&a in main" or "a in Add25". Indeed, if you wrote "int a; int * a;" in main, then you would get errors, because "int * a" is declaring a variable "a" of type int * , but "a" has already been declared. Therefore I think it is better to write "int* a" instead of "int *a". "int *a" is horrible because it implicity declares variable "a", which is in fact the only variable it is declaring, and looks like it is declaring *a here, which it is not.
@julianmahler2388
@julianmahler2388 6 жыл бұрын
Using the same name underlines that main's "a" and Add25's "a" can't possibly be the same variable as you can't declare two variables with the same name in the same scope.
@mozillaexplorer4691
@mozillaexplorer4691 9 жыл бұрын
im getting the error on a brand new clean custom pc. no operating system on it. trying to boot windows 10. first build. will start up. sometimes even asking me for the product key. Help?
@JM-fp3gf
@JM-fp3gf 10 жыл бұрын
This tutorial is GRRRRRRRREAT!!
@ccbrucer
@ccbrucer 11 жыл бұрын
I think if we neglect "*" before the a pointers, it is going to point to an address 100 byetes higher in RAM, for each int has 4 bytes. The pointer +1 will increase 4 bytes in RAM.
@CSryand2m
@CSryand2m 9 жыл бұрын
I think it would have been a better tutorial if there was a visual representation of the heap as well, just to show how referencing is less expensive than copying; however, this was a great tutorial. Thank you!
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
I concur
@oleksijm
@oleksijm 4 жыл бұрын
Awesome vid once again!
@winkiversity
@winkiversity 10 жыл бұрын
best teacher !
@zoranjovanov8564
@zoranjovanov8564 8 жыл бұрын
im still not deep into C++ but i cant change a struct values when i pass it by reference but it works when i pass by pointer. any help why how .. ?
@creelsmusic5814
@creelsmusic5814 8 жыл бұрын
That's pretty weird. What compiler are you on? I was using MS in the vids, I've just checked it now, and it seems to work fine.
@zoranjovanov8564
@zoranjovanov8564 8 жыл бұрын
i use code block GCC/G++ compailer here is the function pretty long and messy but ull get it void switchtype(Type type,Player *player) { switch(type) { case Human :{(*player).lives=1;(*player).stamina=55;(*player).mana=120;(*player).armor=105;(*player).lvl=1;}break; case Elf :{(*player).lives=3;(*player).stamina=50;(*player).mana=150;(*player).armor=85; (*player).lvl=1;}break; case Ogre :{(*player).lives=6;(*player).stamina=35;(*player).mana=100;(*player).armor=110;(*player).lvl=1;}break; case Druid :{(*player).lives=9;(*player).stamina=50;(*player).mana=500;(*player).armor=30; (*player).lvl=1;}break; case Hunter:{(*player).lives=3;(*player).stamina=40;(*player).mana=30; (*player).armor=95; (*player).lvl=1.0;}break; } } when i pass by reference it gives random numbers
@creelsmusic5814
@creelsmusic5814 8 жыл бұрын
Hmmm, that's very interesting. The code looks fine, it looks like fun actually (you coding an RPG?)! Are you passing a player pointer by reference, or just an instance? If you are able, could you test the following code and let us know what it outputs? #include using namespace std; struct myStruct { int j; }; void SomeFunction(myStruct& k) { k.j = 100; } int main() { myStruct q; q.j = 0; SomeFunction(q); cout
@zoranjovanov8564
@zoranjovanov8564 8 жыл бұрын
ya ya it printed 100 so i tried my code again and now its working. no idea why wasnt working before but seems just fine now. thanks for the effort man. nah im not coding RPG xd im just practicing pass by value ,pointer and reference on enums and structs.
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
Forgot, 11:47 you refer to the reference &a as a reference yet you wrote on the screen that's it's the "address of the variable a
@peihongzhong1995
@peihongzhong1995 8 жыл бұрын
Great! Very clear!
@riksharps1972
@riksharps1972 10 жыл бұрын
Nice explaination. Thanks!
@idobooks909
@idobooks909 6 жыл бұрын
11:11 pass by reference.
@yongamer
@yongamer 9 жыл бұрын
Java do not have references or pointers. Is it because java wish to look simple?
@CzipperzIncorporated
@CzipperzIncorporated 9 жыл бұрын
+Vegard Fjeldberg Java has pointers for objects and value types for numerics (int, float, etc). The problem with that is that you can't have a pointer or reference for numerics and can't have a value type for objects.
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
+chimera613 doesn't Java use like a virtual machine to compile or something of that nature? Is that why everything is a pointer?
@hongyionline
@hongyionline 6 жыл бұрын
great lecture!!
@s3anz2
@s3anz2 12 жыл бұрын
Thank you! Very clear
@davey2k12
@davey2k12 6 жыл бұрын
excellent needed this lesson
@ramymohammad8611
@ramymohammad8611 9 жыл бұрын
Thanks for making this clear
@Grinder-one
@Grinder-one 10 жыл бұрын
Great...thanks very much.
@36goldfinger
@36goldfinger 12 жыл бұрын
u speak nice .. great tutorial
@RemixEdits0
@RemixEdits0 7 жыл бұрын
Use a s smart pointer, those are catastrophic prone.
@jurgi888
@jurgi888 12 жыл бұрын
useful comparison, thanks
@MH_Yip
@MH_Yip 9 жыл бұрын
Good, It helps
@ilayasaravanan
@ilayasaravanan 8 жыл бұрын
thanks, it was helpful.
@EvilRobin1
@EvilRobin1 11 жыл бұрын
Thank you very much!
@lachampsfan
@lachampsfan 11 жыл бұрын
well done!
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
Also something you should of pointed out over and over again Is that one can change the variable whereas the other cant change the variable.
@jetolbkk9296
@jetolbkk9296 6 жыл бұрын
big thanks...
@chandrakanthvenkatapuram1946
@chandrakanthvenkatapuram1946 10 жыл бұрын
greattttttttttttttt
@nicholaskhoo8970
@nicholaskhoo8970 11 жыл бұрын
Thanks ! :D
@kritikarai5106
@kritikarai5106 3 жыл бұрын
thank u
@sixpetrov
@sixpetrov 11 жыл бұрын
tnx
@stigtheghost
@stigtheghost 9 жыл бұрын
that was a good one :)
@RemixEdits0
@RemixEdits0 7 жыл бұрын
But good example
@klaus9503
@klaus9503 9 жыл бұрын
Hehehe it's funny how you pronounce "a". You say more "i" than "a" xD. "mine" hehe
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
Ahh you didn't even mention the real differences and advantages of these. That is that one you can change the variable and the other you can't. Sorry man I have to thumbs down this. You would watch other tutorials about pointers and references. They're a lot shorter vids and go over everything. I'll give you credit for the PowerPoint and stack illustration but come on man you really didn't clarify why one would use one over the other. Also you should've did a side by side comparison of the three to show the differences in code. This subject is usually the one that stumps noobs the most and deserves a well laid out tutorial. Noobs say this a great video but they don't know if the info you're teaching is even accurate.
@WhatsACreel
@WhatsACreel 9 жыл бұрын
+christopher jones Thumbs down if you must! I salute your honesty, and if I ever make another vid on the topic, I'll try to remember what you want to hear.
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
+What's a Creel? Haha I must apologize for my super critical comments which I was probably wrong about. I just got out of the hospital and on medication so I'm easily agitated and probably will have a better time watching after my recovery and not under the influence. The docs should put a new note on the bottle "do not operate heavy machinery nor program on c++ while using this medication" Glad you're a good sport. I think I just need to get used to the longer tutorial vids. I'm more used to vids being shorter with the info being broken up and scattered out more into separate videos so it's not as much info to take in all at once. Anyway im a subscriber and you're doing a damn good job cheers.
@genoyostevon10001001
@genoyostevon10001001 8 жыл бұрын
compared to C yeah... you shouldn't program in c++ on medication ... put this in your compiler ...your going to have to space it out.... #include #include #include #include #include #include #include #include using namespace std; char* removePunct(char* word); char reverse(char *); bool palindrome(char[]); int main() { int length; string bob; const int LEN = 64; char word[LEN], *x, *y; coutword; length = strlen(word); cout
@ChristopherJones16
@ChristopherJones16 8 жыл бұрын
bob dole thanks ill give it a go. Im new to these "tokens" are however. Gotta love C++ always something new to learn everyday.
@alfredcalleja450
@alfredcalleja450 7 жыл бұрын
Christopher, why don't you delete this stupid comment!
C++ Tutorial 14: 2D Arrays
20:09
Creel
Рет қаралды 33 М.
C++ Function Pointers 1: Introduction
21:29
Creel
Рет қаралды 10 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Should I pass by const reference or by value?
10:45
The Cherno
Рет қаралды 111 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 335 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 841 М.
What is the Difference Between a Pointer and a Reference C++
7:58
Paul Programming
Рет қаралды 442 М.
Pointers as function arguments - call by reference
14:16
mycodeschool
Рет қаралды 490 М.
POINTERS in C++
16:59
The Cherno
Рет қаралды 1 МЛН
why do void* pointers even exist?
8:17
Low Level
Рет қаралды 396 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН