C++ Pointers - Finally Understand Pointers

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024

Комментарии • 220

  • @codebreakthrough
    @codebreakthrough  Год назад +6

    Check out the hands on guide - ruclips.net/video/u5AH2Wn6h1o/видео.html
    Get notified of my upcoming C/C++ Courses - www.codebreakthrough.com/upcoming-c-cpp-courses

  • @slavsquatsuperstar
    @slavsquatsuperstar 3 года назад +370

    I love how casually this guy speaks. Almost like a friend sharing notes :)

  • @bluerie._.3021
    @bluerie._.3021 3 года назад +241

    I thought of an analogy for when you would use pointers:
    Say you ask a friend to do something regarding an essay you have on an online cloud (calling a function), but to do so, you would need to send them the essay (the arguments). You can either:
    1. Send them a copy of the essay via email/message. This would give them the essay as it was when you sent it, and any changes will not transfer between versions. This means that you and your friend would only be able to see each other's essays if you were to directly communicate with each other.
    2. Send them a link to the spot in the cloud where the essay is in the cloud. The link itself wouldn't be the essay, but they would be able to find the essay by following the link and any changes made by either you or your friend will be visible to anyone that looks at the essay.
    Option 1 would be like directly inputting the variable, while option 2 would be like using a pointer.
    Is this right?

    • @MrBloodman123
      @MrBloodman123 3 года назад +20

      Nice analogy,well explained.

    • @Dazza_Doo
      @Dazza_Doo Год назад +4

      so... DropBox ?

    • @Mr.Legend_9
      @Mr.Legend_9 4 месяца назад

      That's the confusing part with reference

  • @CodeSadhu
    @CodeSadhu 3 года назад +222

    Goddamn you explained this so wonderfully in 15 mins that my professors couldn't in an entire semester lol

    • @AdamMohamed-cq9fv
      @AdamMohamed-cq9fv 3 года назад +10

      literally very fucking true

    • @shivangm24
      @shivangm24 3 года назад +4

      Yes

    • @humann5682
      @humann5682 2 года назад +4

      Almost as though a lot of CS professors aren't always sure of what they are teaching....almost lol!

    • @cheesypizzajokes
      @cheesypizzajokes 2 года назад

      @@humann5682 or just dont care

    • @asmallguy6124
      @asmallguy6124 2 года назад

      @@humann5682 wow didn't know this was common until now lmao.

  • @kevinsuckiel4885
    @kevinsuckiel4885 4 года назад +86

    Finally! Big help for me right now during my class. Thanks dude.

  • @Eddy-ly2ml
    @Eddy-ly2ml Год назад +3

    8:27 was the point of no return where i crossed into learning about pointers all thanks to you Caleb! I love your explanation videos! Thank you for making teaching and explaining these concepts!

  • @lemmiix
    @lemmiix 4 месяца назад

    watched like 10 videos about pointers. That's the one that made me understand how and why use pointers

  • @AleCat97
    @AleCat97 2 года назад +4

    awesome! in my class they are teaching us about pointers and new, delete, null, which seems like the old and harder way of doing things, but thanks for mentioning it in your video! most ppl skip it because its not used frequently but when we have to follow a curriculum from univ is hard to avoid and find info about those. thank u!

  • @mrboyban
    @mrboyban 3 года назад +7

    Hey Caleb, thanks for make this content available,I'm feeling less dumb now.

  • @zinnkazama5022
    @zinnkazama5022 3 года назад

    highly recommended video if anyone didn't get the pointer concept or don't know the use of a pointer, watch this video. Really helpful for me and thank you for the excellent explanation.

  • @lastsuspect137
    @lastsuspect137 3 года назад +8

    int* x seems more readable to me than int *x - it makes it more clear that it's an "int-pointer" ie. its own type, distinct from int. I know there all kinds of arguments about this but I don't care because I'm always right.

    • @n00blamer
      @n00blamer 2 года назад

      I'm with you on this one, all the arguments are blah blah blah multiple variables blah blah.. we're just right it's that simple. :)

  • @WilsonLee123
    @WilsonLee123 3 года назад +6

    The pointer pun 👌 LOL

  • @bradizawsome
    @bradizawsome 3 года назад +16

    You should seriously be a professor or something. You literally made this so much easier for me to understand and you're the only RUclipsr I can find that teaches before coding which is why I only watch your videos lol

  • @Danieldxc666
    @Danieldxc666 3 года назад +17

    Holy... My professor could never explain this so smoothly in half a semester. Thank you!

  • @222ableVelo
    @222ableVelo 3 года назад +5

    This guy just explained pointers the best I've ever heard it explained...........
    and I'm still confused. lol Whoever was the architect of doing it this way in the beginning needs to be tarred and feathered.

  • @kenheisenberg5223
    @kenheisenberg5223 Год назад +1

    This guy is so funny. And very well explained a very difficult and confusing subject.

  • @spacemangalaxy7932
    @spacemangalaxy7932 3 года назад +12

    I don't want to say other lessons bad, it's the best of 5 which I saw about pointers in recommends, and... really understand what it is and how to use it after watching. But, why is here low number of likes, not even 500. Everyone, put likes, this lesson deserves it!

  • @rhysrittgers2183
    @rhysrittgers2183 5 месяцев назад

    I hope you are making millions off these videos because you are helping millions. If you started a goFundMe and asked all your viewers to donate a dollar we would all do it and you would be rich

  • @splatlandss
    @splatlandss 2 года назад

    i had to learn this in the lecture hall equivalent of a hot-locked car, and picked up nothing. I was really scared, but this saved me. And I love CS, so learning this and thinking of how this can improve my code gives me tingles :D

  • @ciaspo
    @ciaspo 3 года назад +41

    Caleb, you figure out what might be difficult to understand and you explain it very clearly. You are a great teacher, keep up the good work! Thank you very much :)

  • @impooser
    @impooser 2 года назад +1

    Very clear and articulated. Keep it up!

  • @Squash101
    @Squash101 Год назад +4

    Certainly the best video on pointers, I wish more people taught concepts like this, rather than just showing a bit of code and syntax

  • @andrewnicastro8400
    @andrewnicastro8400 Год назад

    after weeks of not understanding pointers, I am finally granted some clarity.

  • @Silvertestrun
    @Silvertestrun 11 месяцев назад +1

    Thank you!

  • @shehab976
    @shehab976 3 года назад

    Wow!...so much informative...everybody explains shit in my life about that pointer thing....now i know why c,c++ is that faster❤️

  • @MehrdadKarami-x9w
    @MehrdadKarami-x9w 11 месяцев назад

    Good job on explaining it. Thank you very much. Rock on!

  • @fernm2861
    @fernm2861 Месяц назад

    @8:27 "c programming... disgusting..." I'll repeat that after you as many times as you want! 🙂 But seriously, I love the way you teach!

  • @minh5532
    @minh5532 2 года назад

    :)) To me , it's the first time I see someone writing by left hand . Awesome

  • @gaurishagrawal9404
    @gaurishagrawal9404 3 года назад +6

    I dont know why, but even though C++ is harder...typing it is so much more satisfying .....atleast for me.

  • @trumbaron
    @trumbaron Год назад

    int x = 5
    int *p = &x (adress of)
    x = 5
    &x = 0x5ffe94 (some adress in memory)
    p = 0x5ffe94
    *p = 5

  • @alexandermilleriii499
    @alexandermilleriii499 3 года назад +3

    4:09 As if Hexadecimal "numbers" makes sense lol... hex includes letters. I would just say hexadecimal characters...

    • @codebreakthrough
      @codebreakthrough  3 года назад +2

      Well in hex A-F would be numbers not characters. All kinds of confusing 😉

    • @vlogtomejr.1919
      @vlogtomejr.1919 3 года назад

      I suppose the term "numerals" is likely most appropriate for this context.

  • @mellow_frequencies
    @mellow_frequencies 2 года назад

    Very well explained, thanks Caleb!

  • @KpxRagDoll
    @KpxRagDoll 2 года назад

    Ahahhh that pointer pun at the start got me ngl

  • @wilbertraymundrayos4175
    @wilbertraymundrayos4175 4 года назад +5

    Finally, the video/topic I've been waiting for

  • @ericvt
    @ericvt 2 года назад +3

    been trying to understand this since i was in university. you explained it more clear than my profs lol

  • @islemghz3780
    @islemghz3780 2 года назад

    great video he explain like talking to a friend

  • @imagidan
    @imagidan 3 года назад +2

    Thanks for the pointers LMAO

  • @oisinfeeney3471
    @oisinfeeney3471 4 года назад +5

    Cheers lad, these videos are a great help for uni

  • @DarkReaperK97
    @DarkReaperK97 Год назад +1

    Thanks for uploading. Pointers are terrifying for(almost) every student learning C++.

  • @nickdgreat6741
    @nickdgreat6741 3 года назад +6

    Great video, really helped me get a handle on the concept while keeping it interesting. Thanks for the help and keep doing you bro!

  • @gideon7154
    @gideon7154 3 года назад +1

    that pun almost made me press dislike, never mind the video was amazing

  • @fenfire3824
    @fenfire3824 3 года назад +7

    Pointers are great for "hacking" other software, if it does not have an api. You can find out the memory addresses and read the data of other stuff and use it in your own software. Pretty sure it is violating some policys in a way, but sometimes it is an unfortunate necessarity. It is basicly the same as using cheat engine. Said differently, you can use a tool like cheat engine to find out memory locations and use this in your programs for whatever you need it.

  • @a_boy_can_dream
    @a_boy_can_dream Год назад +1

    You explain things really well. Subbed!

  • @Theanine3D
    @Theanine3D Год назад +2

    I've been struggling with understanding pointers in my C++ course, but your explanation made so much more sense! Thank you!

  • @juniornyembe4841
    @juniornyembe4841 3 года назад +1

    i'm 22 seconds into the video and ive already clicked the like button and subscribed, only from that Pointer joke. amazing

  • @TomtheMagician21
    @TomtheMagician21 2 года назад

    Wow thank you

  • @johnnamtae9610
    @johnnamtae9610 3 года назад +2

    Caleb wazzzzup brothaaaaaaa!

  • @BlackMantisRed
    @BlackMantisRed 2 года назад +1

    I heard someone say you needed points to program a game, I had him explain to me what pointers are but I didn’t understand it or why I would need it, thanks for the great video

  • @ryancarney7616
    @ryancarney7616 Год назад +1

    I was really confused about the meaning of the asterik when using pointers, and how it can be used in a couple different ways. This video really helped clear that up. Thanks!

  • @greywolf271
    @greywolf271 2 года назад +1

    I learnt more about pointers after learning C from the K&R textbook and Michael Daconta's C++ Pointers and Dynamic Memory Managements. Kernighan and Ritchie explain pointers very well and Daconta's book is highly recommended for furthering your knowledge.

  • @nathanmiller9218
    @nathanmiller9218 3 года назад +1

    Is it possible or allowed to define an integer pointer as int* y = &x as opposed to int *y = &x? I know c++ ignores spaces in most situations, but does asterisk placement make a difference in that statement?

    • @burningMallowz
      @burningMallowz 3 года назад

      No, it does not make a difference. Defining a pointer as:
      int* y = &x;
      int *y = &x; or
      int * y = &x;
      are basically the same thing.

    • @josephzamora2676
      @josephzamora2676 2 года назад

      Int* just makes more sense

  • @fortouph
    @fortouph 5 месяцев назад

    I like that you use a white board, I've had difficulties following other coding teachers on youtube who only use the IDE while talking about these topics. I find the whiteboard much easier to follow possibly because I'm a visual learner. You also do an amazing job dumbing down concepts that makes them easier to understand.

  • @nicholascunningham6936
    @nicholascunningham6936 2 года назад

    "Only use pointers when you have to!"
    My professors giving me starter code for an assignment: I'm gonna pretend I didn't see that
    Me, who hasn't touched C++ all summer: tf does this asterisk do again?

  • @CapitalCH
    @CapitalCH 11 месяцев назад

    thank you for posting. i did not understand and my professor hardly explained it.

  • @Joe-qp1ow
    @Joe-qp1ow 4 года назад +2

    You are smart and cute. Haha

  • @ralphramirez7504
    @ralphramirez7504 7 месяцев назад

    My professor constantly reminds us that he has a doctorate masters wizard of oz Jedi degree in computer science and yet Caleb here, explains pointers way better than his bald a$$. Thank you, Caleb.

  • @benlambert8481
    @benlambert8481 5 месяцев назад

    You just made pointers click. it's a type of it's own, just like an 'int' or a 'string'. Rather than putting 'int' the pointer variable is * with a prefix of what variable it is your pointing to... The you give it a name and assign it to the variable you're pointing too.

  • @nicolascrespo4643
    @nicolascrespo4643 2 года назад

    Thanks again! I got the point

  • @calebfurley3784
    @calebfurley3784 11 месяцев назад

    At the end of the video you started firing them little neurons I got, then said “but let’s not get into the weeds we’ll just stop here” 😭 good video though, I wanna move from Java to c++ and this was one of the first videos I watched, so thanks.

  • @about2mount
    @about2mount 6 месяцев назад

    There are no uses for Pointers in programming. Simply use references when passing to void functions instead.
    Also if you do not free or delete your pointers their address is locked in the memory free space preventing other programs access to that memory space.
    So if your machine stores many pointers or repeated pointers that use a different address of these locked addresses they will build up and it will crash and this is exactly why Chrome crashes.
    They can run you out of memory.

  • @favour5442
    @favour5442 2 года назад

    Me wondering if you really use left hand to write or your just showing off your left hand skill😏

  • @Xx_EL_xX
    @Xx_EL_xX 2 года назад

    *doesn’t know the word to describe digits for hexadecimal*
    …then says these numbers aren’t significant. How close can you get hahah

  • @عبدالرحمنالكبيري-ش8و

    In general, pointer is a type of a variable that stores a link to another object. In C and C++, the link is the address of that object in the program memory. Pointers allow to refer to the same object from multiple locations of the source code without copying the object. Also, the same pointer variable may refer to different objects during its lifetime.
    A similar, more restricted type is a reference.
    This section is incomplete
    Reason: restructure the article
    Creation
    A pointer is declared just like a variable but with * after the type:
    -
    int* px;
    This is a pointer, which can point to an integer. The pointer is not yet initialized, therefore it points to an undefined location and any access to it is undefined behaviour.
    What the statement did behind the scenes is to reserve a memory area large enough to hold a memory address on the given system.
    Notice that so far we didn't reserve any memory to hold the integer object that the pointer will point.
    Using pointers
    Assignment and access of pointers:
    int a = 1;
    int b;
    int* px;

    px = &a; /* point pointer to variable a */
    b = *px; /* copy value where px points to into b */

    a = 10;

    std::cout

  • @radioactium
    @radioactium 2 года назад

    if you're initializing the variable *y and setting it to the address of x (&x), why does that same *y call the value at that address and not the address itself when you use it later in the code, since you set it to the address in the beginning? that seems inconsistent to me

  • @TheRawi
    @TheRawi Год назад

    I wish you used a whiteboard instead of using a chalkboard...

  • @williamblair1123
    @williamblair1123 3 года назад +1

    "hexadecimal 'characters' "

  • @larrym1983
    @larrym1983 2 года назад +1

    Oh my god! I luv your explanation of pointers! My professor at school is so confusing so I had to go to youtube to find a better explanation. Your video at explaining pointers is very clear!

  • @tabletalenovo9695
    @tabletalenovo9695 Год назад

    9:10 then why not just write int* y = &x and then cout

  • @safebox36
    @safebox36 2 года назад

    "If you're new to the subject it can be a little bit complicated."
    I learned C++ in university 4 years ago and I still google when to use & and *

  • @TheSimplyJJP
    @TheSimplyJJP 26 дней назад

    Why the heck is it always the youtube videos that make sense and not the professors.

  • @HeatherHolt
    @HeatherHolt 7 месяцев назад

    like given just for the pun at the beginning

  • @paigen8842
    @paigen8842 3 года назад +2

    thanks caleb love you

  • @dawg6408
    @dawg6408 7 месяцев назад

    1 year after high school i'm finally kind of understanding

  • @dw61w
    @dw61w 2 года назад

    Great explanation! Tbh cpp syntax is fucking confusing. *p is the pointer at definition, yet becomes the number afterwards

  • @cclemon2531
    @cclemon2531 Год назад

    thx for helping me learning pointer please continue create more tutorial video!!

  • @anastasiak8589
    @anastasiak8589 3 года назад +2

    Great help in understanding pointers! Thanks Caleb.

  • @NorthernWind_Vlll
    @NorthernWind_Vlll 3 года назад

    Location of this nigga, right here, i died xD

  • @JN-jx7nx
    @JN-jx7nx 2 года назад

    the ridiculous repetition is actually effective cuz I was starting to space out lol

  • @kristiantorres1080
    @kristiantorres1080 2 года назад

    Where's the second part? Amazing video

  • @krup9898
    @krup9898 6 месяцев назад

    This helps a lot. I am taking a college coding class and when we just started talking about references and pointers it was confusing. This teaching series is helping a lot though, thank you! Very fun to watch😊

  • @manikazemi5556
    @manikazemi5556 3 года назад +1

    also, we can call "&" (address of operator) as ampersand operator.

    • @lmaoforgotmaname129
      @lmaoforgotmaname129 2 года назад

      Thanks for your comment, you actually helped me to understand my Problem ^^.
      Please stay well and keep on :D.
      Greetings from Switzerland!

  • @alphagator360
    @alphagator360 3 года назад

    Liked you delivery, how come YT never suggest your channel in my feed, instead it kept suggesting other dumb videos ...

  • @pervbirdmusic
    @pervbirdmusic 3 года назад +3

    "Alright, let's learn how to use pointers!"
    "Use references instead."
    "Aight, cool."

  • @NoSpeechForTheDumb
    @NoSpeechForTheDumb 2 месяца назад

    Pointer in C: int *p
    Pointer in C++: std::unique_ptr p

  • @greywolf271
    @greywolf271 2 года назад

    Digit does'nt imply base 10 at all and never has. If you look up the dictionary meaning of digit, it used to be an ancient method of signifying a unit quantity.

  • @DMS20231
    @DMS20231 Год назад

    No offense intended to some of our brethren, but some of them are impossible to understand. I love how clearly and casually Caleb speaks.

  • @Zain-ks8ws
    @Zain-ks8ws 3 года назад

    Caleb, is it Indian Curry or English Curry?

  • @LorenzoMezzabarba
    @LorenzoMezzabarba Год назад

    pointer are way easier that i thought, nothing compare to recursion

  • @akshatvats7992
    @akshatvats7992 4 года назад +2

    Real programers call the asterisk 'star'

    • @codebreakthrough
      @codebreakthrough  4 года назад +10

      Really real programmers call it capital 8.

    • @akshatvats7992
      @akshatvats7992 4 года назад

      @@codebreakthrough In Python 4, '8'.upper() will return *

    • @umarhasnain7369
      @umarhasnain7369 3 года назад

      @@akshatvats7992 Is it 3.9 maybe? Just came recently.

    • @akshatvats7992
      @akshatvats7992 3 года назад

      @@umarhasnain7369 It must be in like ultra-beta. Because otherwise I would have received it while updating my system.

  • @SebleBeyene-jp8hp
    @SebleBeyene-jp8hp 6 месяцев назад

    I feel sorry when i didn't laugh 😂😂😂

  • @LowLevelStudio
    @LowLevelStudio 6 месяцев назад

    Just try combination of & and * until it works

  • @소피-e2e
    @소피-e2e 2 года назад

    Nice! Thank you! I guess that is why people prefer to declare with int* y instead of int *y to avoid confusion
    the only thing i dont like about this video is the fact that you use blackboard it hurts me soo much haha

  • @rickstead8189
    @rickstead8189 3 года назад

    it would be easier to understand if you actually said you put * next to "int" not "y" that's why it's called int pointer

  • @DroopNasty
    @DroopNasty 2 года назад

    Hey Caleb, hope you're doing well my dude

  • @kristiantorres1080
    @kristiantorres1080 2 года назад

    subscribed right after the pointers joke

  • @charicner
    @charicner Год назад

    lifesaver, Pearson's textbook is trash

  • @Lin_The_Cat_
    @Lin_The_Cat_ 2 года назад

    Just *had* to subscribe after that pointers pun.

  • @KnitterX
    @KnitterX 3 года назад

    So what's a use case where a pointer would be necessary? If I understood correctly all the examples you are giving here could also be done with references. In fact, you used the same examples in the references video.

  • @purpleorange8898
    @purpleorange8898 2 года назад

    sellojut having sponsor🤓🤓🤓

  • @afsarabushra1769
    @afsarabushra1769 2 года назад

    I am in school and they are making us learn pointers. we arent allowed to use references lmao