Pointers - CS50 Shorts

Поделиться
HTML-код
  • Опубликовано: 24 окт 2017
  • ***
    This is CS50, Harvard University's introduction to the intellectual enterprises of computer science and the art of programming.
    ***
    HOW TO SUBSCRIBE
    ruclips.net/user/subscription_c...
    HOW TO TAKE CS50
    edX: cs50.edx.org/
    Harvard Extension School: cs50.harvard.edu/extension
    Harvard Summer School: cs50.harvard.edu/summer
    OpenCourseWare: cs50.harvard.edu/x
    HOW TO JOIN CS50 COMMUNITIES
    Discord: / discord
    Ed: cs50.harvard.edu/x/ed
    Facebook Group: / cs50
    Faceboook Page: / cs50
    GitHub: github.com/cs50
    Gitter: gitter.im/cs50/x
    Instagram: / cs50
    LinkedIn Group: / 7437240
    LinkedIn Page: / cs50
    Reddit: / cs50
    Quora: www.quora.com/topic/CS50
    Slack: cs50.edx.org/slack
    Snapchat: / cs50
    Twitter: / cs50
    RUclips: / cs50
    HOW TO FOLLOW DAVID J. MALAN
    Facebook: / dmalan
    GitHub: github.com/dmalan
    Instagram: / davidjmalan
    LinkedIn: / malan
    Quora: www.quora.com/profile/David-J...
    Twitter: / davidjmalan
    ***
    CS50 SHOP
    cs50.harvardshop.com/
    ***
    LICENSE
    CC BY-NC-SA 4.0
    Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
    creativecommons.org/licenses/...
    David J. Malan
    cs.harvard.edu/malan
    malan@harvard.edu

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

  • @ezzenious9923
    @ezzenious9923 3 года назад +93

    Man I feel sorry for the people who might be skipping over these shorts. The main lectures are great but Doug just clears up so much for me here.

    • @bpospanov
      @bpospanov 10 месяцев назад +4

      Agree. I am one of those people who skipped shorts and now I have to get back and watch them

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

      @@bpospanov made the same mistake, catching up right now, and so many things have become much clearer for me ..

  • @OT-oi8kl
    @OT-oi8kl 3 года назад +32

    Bro, like literally no one has explained pointers in depth or as well like you have in this course. WHY are CS teachers not great at explaining this. It's like they expect us to hear their metaphors and completely understand how to code a pointer. I appreciate you going through all the logistical things that students get confused about, like why is there a asterisk on that value but not the other we, and why to we use ampersand sometimes. I think the teachers just assume we are either smart or dumb, but in reality we can only start learning once something makes sense to us logically, rationally, and most importantly if we know WHY we are doing this. I really wish my previous teachers would have just shown me this video.
    Also pass by reference and values makes so much more sense to me now. Arrays are basically pointers but with no *, and the goal of using a * is to get a normal variable (char or int, whatever) to act like an array. Arrays are pass by reference and variables normally are not. The reason we might want this is because variables DON'T SAVE VALUES when we put them into functions (aka if variable x is put into a function where x = "hi", the end result will not save x as "hi" because this is pass by value). But array do get saved in functions. If we want to save values into variables just like how arrays automatically do (from inside a function), we use pointers.
    IDK why I wrote this, I think just to vent and help myself understand this. I've been struggling on pointers for soooo long, thank you really, I appreciate it a ton.

  • @neo5020
    @neo5020 5 лет назад +229

    Pro tip: Instead of declaring pointers as type* name, you can just declare them as type *name (there's no difference). This'll prevent any confusion that you might get from declaring multiple variables at once on the same line as stated at 23:49.

    • @fatadel
      @fatadel 5 лет назад +6

      That's the question I was wondering throughout all time! Thanx for your tip, Neo!

    • @AlexandreMiguelf
      @AlexandreMiguelf 5 лет назад +28

      (int* a = pointer) (*a = value stored on 'a' address) i think writing like this it's better for understanding because are different things

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

      That's also what they doing in the CS50 lectures (at least in the 2019 version)

    • @chrislam1341
      @chrislam1341 4 года назад +8

      @@AlexandreMiguelf i agree, "unpack" the actual value in the memory while a is a data type, aka pointer, that stores reference(address), writing in this style is more intuitive

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

      personally i like: type * name

  • @brandonthompson9659
    @brandonthompson9659 6 лет назад +133

    This is amazing. Finally some C videos that are clear and understandable. Thanks! These are going to be lifesavers this semester.

  • @stovegamesgames6917
    @stovegamesgames6917 4 года назад +9

    Two weeks worth of reading and lectures compressed into a few minutes that make 50 times more sense

  • @daviddalisay5317
    @daviddalisay5317 6 лет назад +65

    For me, this is easily the best video on pointers on youtube. I wish I had this during my CS undergrad!

  • @jackbower2204
    @jackbower2204 5 лет назад +38

    Im a first year student of computer science at a local community college, just wanted to say thank you to the cs50 team, their tutorials and lectures are so much better and clearer than my school's. Got the aha moment immediately after this video, Lloyd and David are great at breaking down confusing topics and making them very comprehensible. Appreciate the help, wish you guys had all the CS classes at Harvard, but I guess thats asking too much.

    • @SaadKhan-kk4ni
      @SaadKhan-kk4ni Год назад +3

      brother has hopefully graduated

    • @rubiano3
      @rubiano3 Год назад +3

      @@SaadKhan-kk4ni I hope so

    • @artikz7349
      @artikz7349 9 месяцев назад

      @@rubiano3i hope so as well

  • @najemabaakil29
    @najemabaakil29 5 лет назад +13

    The notebook analogy was incredible! I’m not used to working with pointers but that part alone really cleared everything up. Keep up the awesome work!

  • @schoukah
    @schoukah 4 года назад +4

    Doug Lloyd you are the best! Thank you so. so. so. much. Can finally wrap my head around pointers!

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

    The way how he explained pointers was really comprehensible. Thanks Dougg, best video so far :)

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

    Thank you very much, David Malan and everyone on cs50 staff!! You´re amazing . All that for free is just unbelievable!

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

    Beautifully explained Doug. Found your description and explanation so easy to follow.
    Of course, it's going to take me a while to understand ti well enough to implement them into my work but that's on me!

  • @gtoloki777
    @gtoloki777 Год назад +3

    It's been some years ago, but with headphones the "puff" sound from some midlow voice frequency could be diminished by putting a bit down around 500hz into the sound mix.
    This video helped a lot. Doug you did great here.

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

    Don't give up. Yesterday it seemed impossible to understand, today it's already much clearer.

  • @poluefemus
    @poluefemus Месяц назад +1

    27:13 the conclusion is probably the most useful part of the video

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

    Doug my man, i want to hug you mate, thanks for the incredible explinations, so much make sense now... Keep the great work

  • @MadJDMTurboBoost
    @MadJDMTurboBoost 5 лет назад +1

    Amazing video series! Absolutely clear and well formulated examples. Thank you so much for your time and effort you really do make the internet (and the world) a better place.
    On a side note, I wish you would go more into the syntax like using pointers to structs and accessing the instance variables using -> etc.

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

    I was so confused right up until the very end in the final diagram where you showed the k and *pk, I finally understand how to use a pointer, thank you so much.

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

    The best explanation of pointers I've seen or read so far (as a beginner).

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

    Awesome video! Straight to the point, easy to follow, and full of useful info. Thanks!

  • @pastafarian8410
    @pastafarian8410 4 года назад +1

    Dereferencing was the part , I used to get stuck up . You just nailed it mate .Cheers

  • @lamebrisee
    @lamebrisee 5 лет назад +13

    OMG . wish I had a C language teacher like you 20 years ago !! thanks a million

  • @d.k.1545
    @d.k.1545 6 месяцев назад

    Love what youre doing Doug.
    Huge thanks!

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

    Simply amazing how good this video is.

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

    Great video. I finally understand pointers. I also recommend others' in this comment section to search for "call by reference vs call by value" to really cement the concepts. Thank you!

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

    My man Doug dropping shorts like they're unskippable DLCs lmao

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

    Thanks for this video; before this I was using pointers sometimes to get something working but the next time i use it, i know what i'm doing :)

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

    Watching these shorts after the main lecture is very helpful

  • @user-lm5ju8nc2t
    @user-lm5ju8nc2t 5 лет назад

    Love CS50! Very good explanations. Guys, you are the best))

  • @shivambhanu2757
    @shivambhanu2757 5 лет назад

    finally i understood pointers so well . THANKS Lloyd

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

    Thanks a lot Doug, you've been really helpful.

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

    I really like when he says "it's a lot easier to think about it like that as a human being" XD

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

    thanks doug, once again a great summary to a abstract topic

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

    Thanks Mr. Lloyd, you are a good teacher!

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

    I think you have phenomenal teaching skills. Bravo!

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

    Holy cow I think I'm starting to understand pointers in C!!! Thank you CS50! :D

  • @tom1325
    @tom1325 9 месяцев назад

    Really good job, Doug! Thank you

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

    The syntax distinction between the two uses of * in the context of pointers is very useful to me: int* c (declaration of pointer) and *c (dereferencing that pointer). The lecture isn't (always) always doing this, e.g. declaration of pointer p in lecture 4: int *p.

  • @JKSmith-qs2ii
    @JKSmith-qs2ii 3 года назад +118

    Is my laptop dying or are there sometimes horizontal lines appearing onscreen?

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

    The last 5 mins of this video helped me a lot. I guess it's mainly because I am not a native English speaker. Most part of the speech just drifted in front of eyes.

  • @enisarik6002
    @enisarik6002 4 года назад +1

    The moment that he explains that string is actually the collection of characters, but not a data type.. Oh man! I feel enlightened!!! :D

  • @andrerossa8553
    @andrerossa8553 5 лет назад +1

    amazing lecture, thanks a lot

  • @kaliomar5988
    @kaliomar5988 5 лет назад

    amazing work keep on great CS50

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

    Thank you! This is a life saver

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

    What can I say? Absolutely clear and smooth explanation of pointers

  • @andreysantos6660
    @andreysantos6660 5 лет назад

    Amazing explanation, thanks!

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

    Thank you, Doug Lloyd!

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

    I totally agree that what makes pointers so complex is its syntax. sometmes * is just literally a symbol represnetating it is a pointer when you declare it, and then next time, it's a dereference operator where it takes you to a value pointed by a pointer address

  • @luckydevil1601
    @luckydevil1601 10 месяцев назад

    Amazing video, thank you so much!😍

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

    Great material, thank you.

  • @marsuperez
    @marsuperez 4 года назад +8

    Awesome video but for a moment I thought my screen was broken with all the green lines 😂

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

    This video has some really useful pointers.

  • @r.nurtsawaabitfaheimys9213
    @r.nurtsawaabitfaheimys9213 Год назад

    Finally, I'm here to understand more what pointer is.

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

    thank you so much for this

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

    I understand a pointer as a variable that holds the address of another variable. to extract the address of a variable, we use the & operator, which returns a pointer. derefencing is a way of getting the value located in memory. to achieve dereferencing we need the address of a varible.

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

    thank you Doug!

  • @lhliang9114
    @lhliang9114 4 года назад +1

    Good explanation! The only issue is "all pointers are just addresses". Actually pointers are variables which contain the address of another variable.

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

    "When we learn the difficult, everything else become easy". I mean, I think if we become experts in Pointers, so the entire C will become easy to learn and I guess that, all programming languages becomes easy too, like a domino effect. Awesome lesson Professor Doug Lloyd, thank you.

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

    @17:47 it was actually the Arrays Short where set_int and set_array were used; not Variables And Scope

  • @itsmikeneas
    @itsmikeneas 6 лет назад +43

    I wish this video came out when i was in undergrad haha

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

    Thanks a lot!

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

    Pointers are especially useful when you have an array of objects and you don't know which object stores this specific value and you wanna make a change to the object so you use pointers so you can actually change it.

  • @MohamedUsama1
    @MohamedUsama1 6 лет назад +1

    that helped a lot , thx :)

  • @parasbansal
    @parasbansal 6 лет назад +4

    Hey Doug, great video! Although, i had a doubt. Do the light green boxes (pointers) take memory and if we free(some pointer), do the light green boxes always remain in memory or what ?

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

    Between the lecture and the short I’m surprised there hasn’t been a mention of developing a naming convention that makes it obvious if a variable is a pointer or an actual variable. Something like ending all pointer names with an underscore

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

    kid: "mom, can i watch shorts from harvard cs50?"
    mom: "no, we have shorts at home"
    *shorts at home - 30 minutes

  • @Pavel-wj7gy
    @Pavel-wj7gy 9 месяцев назад

    I think it would be worth showing the "->" syntax for de-referencing struct properties.

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

    youuuuu doug Lloyd help many peoples in brazil, thanks!

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

    very useful video!

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

    so helpful, thanks

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

    arrays aren't just pointers. they are similar, but 1. they support different notation for accessing the memory they point to (no asterisk asterisk), and 2. you can't change the memory address an array variable holds, whereas you can change the address a pointer variable holds. when you pass an array to a function, the argument will be a pointer containing the same address the array points to, this is also referred to as an array "decaying into a pointer"

  • @Trungao-dz1cy
    @Trungao-dz1cy Месяц назад

    thanks Doug

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

    please please please do some video on the difference between char *arr[] and char (*arr)[]

  • @bensmith9253
    @bensmith9253 6 лет назад +4

    great video

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

    Thank you sir

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

    My mind exploded when he talked about 32 and 64-bit systems. Does that mean that the NES, an 8-bit system, can only store addresses (pointers) up to 0xFF?

  • @freaksh0
    @freaksh0 4 года назад +1

    I take that pointers work like global variables, since locally scoped variables cannot be changed outside of their scope. With a pointer you can access it and change it from anywhere just like you could do with a global variable ??

  • @yasseralbrikeet4323
    @yasseralbrikeet4323 4 года назад +7

    At 17:76 when you refer to the example on Variables and Scope, actually it was the example at the end of Arrays video! ruclips.net/video/YdSycMcxvY0/видео.html

  • @riomanz7769
    @riomanz7769 5 лет назад

    I really should talk to my dean about hiring teachers like u, you are soo good in delivering the message

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

    thank u i under stand

  • @St4rrk.
    @St4rrk. 2 года назад

    If you take the context out of it, that neighbor's house part is very funny

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

    what data item is also used to hold the address of a pointer? Also why can't strings be used to hold the address of other variables sine the hexadecimal notation is a string

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

    This is the only pointer tutorial that actually explains there are 2 uses of *

  • @bertramusb8162
    @bertramusb8162 4 года назад +1

    Is no one going to mention the little black dot flying back and forth on the screen starting around 15:12 ?

  • @yitto4965
    @yitto4965 6 лет назад

    this one was good

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

    question: at the end, when you said pk gets the address of m, does it mean the hex in pk then is changed to a whole new value?

  • @Brandon-gy6rt
    @Brandon-gy6rt 3 года назад

    lmao when ur uni prof doesnt explain anything, so u came to here !!! it was helpful thankyou

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

    Thanks

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

    BUT why do we use pointers at all. I mean why dont we just work with different variables at once but use pointer to point at an adress which in fact just takes the information stored in that adress its pointing at and stores in it self. Why dont we just use the Variable we point at in the first place. Thats the question I dont understand....

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

    also, these are virtual addresses. C programs work under the assumption they "own" the entire memory space, and the OS gives them a fake memory address starting from 0 to make it simpler for individual programs, but the OS may allocate bytes, even those of an array, all over the place, and the conversion of virtual to physical space is done by the OS or CPU under the hood.

  • @rokeshp2638
    @rokeshp2638 9 месяцев назад

    17:32 ain't arr[i] refer to the i+1 th element of the array? cause arr refers to the address of the first element, arr +1 to the second element and so on. correct me if I am wrong.

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

    This videos awesome but somebody messed up the premiere export settings

  • @06jone
    @06jone 4 года назад +1

    I'm surprised I was this video's first like. This is great! Thank you.

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

      Hello, I'm from the future here to tell you that you were not the first like, they have the likes disabled on this video so you cannot see the current number of likes.
      Thank you.

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

    @17:40 I don't see how the implication is that arrays names are just pointers. Like you made that leap.

  • @espedale
    @espedale 5 лет назад +21

    When you say that "all pointers are just addresses", don't you really mean that all pointers are VARIABLES that hold an address? Otherwise it's too abstract. If I am understanding correctly, a pointer is not the address itself, but rather a memory location (represented by a *variable) that holds the "gps" coordinates(i.e. address) to a different memory location where the values (stored in binary) actually physically live in RAM world.

    • @mohammedjawahri5726
      @mohammedjawahri5726 4 года назад +7

      The way I've always thought about it is this. A pointer is just a variable. It would make no difference WHATSOEVER (if I'm not mistaken) if you say int p = &x , the star just tells the compiler that you INTEND to put some address inside that variable. Because at the end of the day it's just numbers, zeroes and ones, all a pointer is, is simply a variable that happens to hold zeroes and ones that represent an address in the memory rather than a value that you want to use directly

    • @enisarik6002
      @enisarik6002 4 года назад +1

      @@mohammedjawahri5726 Agree. It is just a variable that meant to be pointing an address in memory. But it is also stored in memory and it has its own address.

    • @benfrese3573
      @benfrese3573 4 года назад +1

      @@mohammedjawahri5726 Yeah, almost :) This here won't work "int p = &x" since the address of x isn't an integer. But in general I think you're right.

    • @julioandres1074
      @julioandres1074 4 года назад +1

      This is so much simpler and easier to understand(at least for me).

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

    so * is not used to make something into a pointer? it is just used for dereferencing?

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

    When you just finished watching a 2hr and 40 min video, just to watch another few hours more..
    Oh god help me

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

    Pointers aren't real, they are just addresses, they can't hurt you. CS50 problem set:

  • @Naz-yi9bs
    @Naz-yi9bs 4 года назад

    Does this apply to the Python pointers?

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

    That was useful