Pointers in C for Absolute Beginners - Full Course

Поділитися
Вставка
  • Опубліковано 28 вер 2024

КОМЕНТАРІ • 195

  • @rowancode
    @rowancode Рік тому +67

    I just started learning C/C++ and this gets dropped, definitely you guys are amazing, thank you for the course! This is really helpful

    • @UToobUsername01
      @UToobUsername01 Рік тому

      I used to learn C and it got me back into wanting to re-learn all of the stuff I forgot. I think I have many "learn how to code in C" books lying around but I ended up stopping right about the part where it got into pointers. lol

    • @nkazimulojudgement3583
      @nkazimulojudgement3583 Рік тому

      @@UToobUsername01 you dont work with C anymore?

    • @beepbeepgamer1305
      @beepbeepgamer1305 11 місяців тому

      are you still learning c? I just started learning c since there's an paper for c in my clg. C is tough ngl, how is it going on for you?

    • @armincal9834
      @armincal9834 10 місяців тому

      ​@beepbeepgamer1305 imo c is actually the easiest language there is,but because it's so simple,writing anything more complicated than a text manipulation program is a pain because the language almost doesn't do anything for you

  • @anguswalker7511
    @anguswalker7511 Місяць тому

    This is AWESOME. Very concise, excellent video. Well organized and jam packed with golden nuggets of interesting and relevant information. Keep up the great work!

  • @rensukiyo
    @rensukiyo Рік тому +16

    1/2
    Some key notes (not detailed and please correct my understanding where necessary):
    The main function is BOOM the big bang of the program where the code starts executing. This function sets off a chain of calls and returns from other functions. Nice diagram at 16:24
    Naive change_value program (code at 23:02)
    -nb is an int variable set to 42. the nb variable is passed to the change_value function. Within the change_value function, nb is set to 1337. Now in the main function, nb is printed. What will the value of nb be?
    - The answer is nb will still have the value of 42. Why? This is because the variable nb is passed by value and not by reference. Basically a copy of the variable is passed to the change_value function rather than the memory address where the variable is stored. This means that change_value changes the value of a copy of nb to 1337 rather than the original nb variable.
    change_value program with pointers (code at 32:45)
    -So how would you change the original nb variable?
    -The answer is to pass a direct reference to the nb variable address AKA a pointer!
    -The code is changed such that change_value's parameter is a pointer (designated with asterisk (*) before variable name), the variable name is changed to foobar
    -*foobar is assigned the value of 1337 (The variable stored at the foobar pointer is assigned 1337) (foobar refers to the pointer that stores the address while *foobar refers to the variable stored at this address; referring to the variable stored at the address is called dereferencing)
    -Instead of creating an nb pointer in the main function the nb address can be passed directly as &nb
    -Now nb is successfully changed to 1337! We are dealing with the same nb variable stored in the same memory location rather than a copy of the nb variable!
    Classic Swap (code at 33:40)
    -a is an int variable assigned 42. b is an int variable assigned 1337. swap is a function that will switch these values using pointers. First, the addresses of a and b are passed to swap as parameters.
    -In the swap function, a is referred as n and b is referred as n1 (based on order when swap is called).
    -To swap the values, the int variable tmp is created to temporarily store n's value. n is then assigned n1s value. Finally, n1 is assigned n's original value.
    -Line 7 n is dereferenced, Line 8 n and n1 are dereferenced, Line 9n1 is dereferenced. Dereferencing simply means dealing with variables rather than the memory locations where variables are stored
    Why declaration and dereference have the same syntax? (34:05)
    -Worth watching this section, it is concise
    The main benefit of passing by reference is that you don't need to make a copy and therefore you save memory especially if you are passing something large like a large array
    Pointers have the same size for different data types, an analogy for this is that the empire state building address and a small restaurant's address are the same size, even though the size of the buildings are different
    If pointers are the same size, why do pointer types have to be specified? (pointer type = type of variable achieved by dereferencing pointer)
    Basically, different different data types are stored differently in a way that impacts pointer functionality. chars take up 1 byte, ints take up 4 bytes. (One memory address correlates to one byte)
    One example of how functionality is changed is pointer arithmetic:
    if pc is a char pointer (chars are 1 byte, a memory address holds 1 byte), and pc refers to the memory address 0x7ffeea5f930, pc + 1 would refer to 0x7ffeea5f931, pc + 2 would refer to 0x7ffeea5f932
    if ptr is an int pointer (ints are 4 bytes, a memory address holds 1 byte), and ptr refers to the memory address 0x7ffeea5f930, pc + 1 would refer to 0x7ffeea5f934, ptr + 2 would refer to 0x7ffeea5f938
    Pointers can be type casted (the pointer type is changed) line 13 in code at (50:57) which changes how the compiler interprets the variable stored in the pointer. Basically the pointer can act like the variable it is associated with is of a different type, while the actual variable is unchanged. I know this is confusing, please call me out if I am wrong about anything.
    As stem cells can become any cell type, or actors can be assigned any role, void pointers can later be assigned a data type.

  • @minimalSwift
    @minimalSwift Рік тому +4

    This is just the best course about pointers that I found online! 😀

  • @MarcusHCrawford
    @MarcusHCrawford Рік тому +4

    I don’t understand how you guys always know what I’m Googling.

    • @techdoctorP
      @techdoctorP Рік тому

      Brooooooooo.... It's wild..

    • @rusi6219
      @rusi6219 9 місяців тому

      They're in your walls

  • @AndersonSilva-dg4mg
    @AndersonSilva-dg4mg Рік тому +4

    Hooray! Thanks for lession.

  • @yeyintaung9837
    @yeyintaung9837 Рік тому +7

    The very topic why I left c .now I am gonna try again ❤

    • @JackHotail
      @JackHotail Рік тому

      "C and assembly are great starting points in the world of programming."

    • @benjwilliams5104
      @benjwilliams5104 Рік тому

      Best of luck! You got this!

  • @AwaisFarooqi-dy1cp
    @AwaisFarooqi-dy1cp Рік тому +2

    This help students alot because pointers is difficult for students in programming

  • @ElementX.
    @ElementX. 2 місяці тому +1

    Someone needs to show this to CrowdStrike Developers.

  • @renanlins3916
    @renanlins3916 Рік тому +3

    You could enable close captions.

  • @giacomo1439
    @giacomo1439 11 місяців тому +1

    Saved the video for first year at university

  • @veorEL
    @veorEL 9 місяців тому +1

    At 31:25 you say everything works thanks to the power of pointers, but in the slide, the initial value is the same as the one you are changing it to ... I mean, it works like you say, but the initial value is identical to the changed value not sure why you changed it from 42 on the previous slide ... don't forget to get your slides reviewed

  • @onaecO
    @onaecO Рік тому +68

    All the Code used and few notes here:
    medium.com/@jalal92/just-dereference-the-link-for-the-code-in-the-video-cdfc0c2d9547
    I learnt myself a lot with freeCodeCamp and now, crazy enough, i produce myself tutorials!
    I will always be a promoter of this amazing project, empowering people for free all over the world.
    A particular mention to Beau that allowed me to be part of this, such a gentleman! ❤

  • @caffe2285
    @caffe2285 Рік тому +3

    It's rather useful to rewind the video if you do not understand. A random passerby

  • @rul1175
    @rul1175 Місяць тому

    Wow awesome video. Thank you for your contribution.

  • @danypell2517
    @danypell2517 Рік тому +2

    C IS HIGHLY EFFICIENT!

  • @sairajdas6692
    @sairajdas6692 Рік тому +1

    Brilliant video. Also subbed and clicked the bell. Waiting for your next video.

  • @josephaj8310
    @josephaj8310 Рік тому +2

    We also need a handlebars(hbs) tutorial as it will be very helpful since there is no tutorial for hbs in YT.

  • @bresent
    @bresent Рік тому +3

    i love C

  • @arduinoguru7233
    @arduinoguru7233 10 місяців тому

    one of the best videos so far.

  • @slowcoding
    @slowcoding 5 місяців тому +1

    감사합니다.

  • @manfredbogner9799
    @manfredbogner9799 9 місяців тому +1

    very good

  • @kevincodes674
    @kevincodes674 Рік тому

    Brilliant, very well explained. Thank you for sharing your insight.

  • @mhalton
    @mhalton 2 місяці тому +3

    One correction: MacOS is NO king!

  • @Tusharmanchanda-uz8xp
    @Tusharmanchanda-uz8xp Рік тому +1

    Great tutorial

  • @Naoty_san
    @Naoty_san 10 місяців тому

    wow, it makes me understand things! Thank you!

  • @anesmekhoukh
    @anesmekhoukh Рік тому +1

    why there is turing picture in the backgroud in ide ?

  • @destinyobamwonyi8865
    @destinyobamwonyi8865 11 місяців тому +1

    Am I the only one curious about his vim setup. please how did you do that ?

  • @guillermoezequielperna9674
    @guillermoezequielperna9674 8 місяців тому

    Thank you very much for this content!

  • @tesfalemeshetu4675
    @tesfalemeshetu4675 7 місяців тому

    Simply the best 👌

  • @vicsteiner
    @vicsteiner 4 місяці тому

    Thanks for the video! Funny that in the compiler I have, gcc that came in my ubuntu distro, the example at around 59 minutes leads to a segmentation error, it does not print the int 42. Printing the address I see it is (nil), so it seems that when the stackframe for foo goes away the pointer is nil. I am not sure though if this happens because the compiler assigns nil to any function that tries to return an address to a local variable or else?

  • @Trick1e
    @Trick1e 4 місяці тому

    Thank you, my friend =)

  • @ascendedbox612
    @ascendedbox612 Рік тому +3

    Your videos have helped me so much!

    • @haniissa1990
      @haniissa1990 Рік тому

      how his video helped you if you just watch less then 10 minutes? and the video uploaded before 11 minute?💩

    • @ascendedbox612
      @ascendedbox612 Рік тому +2

      @@haniissa1990 I didn't watch this one? I used his python playlist. Why are you so argumentative?

  • @abdulrhmanibrahim1127
    @abdulrhmanibrahim1127 Рік тому +1

    Thx ❤

  • @hadeseye2297
    @hadeseye2297 9 місяців тому

    Video by itself is great, but there's one issue. That constant squelching is quite irritating. It's a habit you can unlearn, and it will improve your speech a lot.

  • @forheuristiclifeksh7836
    @forheuristiclifeksh7836 2 місяці тому +1

    35:00

  • @egecanbek9562
    @egecanbek9562 Рік тому +1

    I don't understand the joke between bit nibble and byte. 7:10 can someone explain? I am not a native speaker. What is that mean '4 bits are enabled'

    • @priyaghate522
      @priyaghate522 11 місяців тому +1

      when we just nibble at food when we arent that hungry.. thats called nibble and when we really feel hungry we bite the food .. thats what hes trying to say.. nibble and bite (byte) is sort of related to food analogy, i hope you understand what im trying to say :)

  • @wribbit
    @wribbit 7 місяців тому

    Thanks for the video!
    Can someone explain, at 32:47, why do we need line 3? The function change value is already present at line 14 onwards.

    • @zDoubleE23
      @zDoubleE23 6 місяців тому +2

      Line 3 is called a “prototype.”
      Notice that when used in main(), change_value isn’t defined until line 14. This would cause the compiler to reject the code.
      So using a prototype allows programmers to define the function before main() in order to avoid this error.
      Note that prototypes require the “;” whereas creating the function does not.

  • @woosukbyun2455
    @woosukbyun2455 6 місяців тому

    who is the lecturer of this video??!

  • @marcellogambetti9458
    @marcellogambetti9458 5 місяців тому +1

    pointer for abs beginners, the first example is a triple pointer, not very clear sorry.

  • @anime-fights9123
    @anime-fights9123 Рік тому +4

    Do you have a video with generic pointers and memory by increment, also data structures with generic pointers.

  • @RJJ-px7hm
    @RJJ-px7hm Рік тому +1

    I know less about pointers now because of this video, very confusing.

  • @_powerbeard
    @_powerbeard Рік тому +1

    Not to be contrary, but pointers and absolute beginners is going to lead to overwriting all manner of memory.
    I know, I taught new employees to code in C.
    But you gotta start somewhere. Or skip and do Rust.

    • @sarahyukino7213
      @sarahyukino7213 Рік тому +3

      Does Rust not have pointers? I thought references and dereferences was about pointers

    • @_powerbeard
      @_powerbeard Рік тому +3

      @@sarahyukino7213 Rust kind of has pointers but they are safe. In fact, Rust is so well designed that programs often work properly the first time you get them to compile, logic issues notwithstanding.
      Getting your code to compile can be mind bending though.
      I 100% think learning C pointers is time well spent. With function pointers and varargs, you can build polymorphic objects, and simulate an OO language. It's how C++ originally worked, it was compiled down to C (very interesting) code. Fun stuff.

    • @이주연-g4f5q
      @이주연-g4f5q Рік тому +1

      As a cs student who wants to learn more about the computer systems, do u recommend c or rust?

  • @blazebluerusso8925
    @blazebluerusso8925 Рік тому +2

    who is here from alx???

  • @subeeradam098
    @subeeradam098 Рік тому +1

  • @zolambunga5582
    @zolambunga5582 10 місяців тому

    could you teach how you turn the gcc and ./a.out code into one function? You named it "r", how do I do that?

    • @CabernetKing
      @CabernetKing 8 місяців тому

      gcc example.c -o example && ./example
      The -o part stipulates what you’ll name your program instead of the default ‘a.out’

  • @zaman.tasiin
    @zaman.tasiin 4 місяці тому

    38:31

  • @Rahul-yu3ro
    @Rahul-yu3ro 10 місяців тому

    13:32

  • @seya2183
    @seya2183 Рік тому

    I'm piscine 42 ecole this moment.

  • @sadness2739
    @sadness2739 Рік тому

    what does that 1337.42 mean :)

    • @Tugahz
      @Tugahz 20 днів тому

      1337 is the belgian variant i think of the 42 school, free programing school, he probably got examples outta that

    • @sadness2739
      @sadness2739 20 днів тому

      @@Tugahzyeah I know I study there

  • @seymur72
    @seymur72 7 місяців тому +1

    if you like live long then doesn't learn c :)

  • @gerrymills3332
    @gerrymills3332 Рік тому +2

    What the f#&k is he talking about 😢? It's supposed to be a teaching aid for beginners!

  • @piotreusz475
    @piotreusz475 Рік тому

    I hate emojis in this video. Please consider change that style, cause for me it was very disturbing to learn

  • @arnaVck
    @arnaVck 9 місяців тому

    11110

    • @arnaVck
      @arnaVck 9 місяців тому

      1+F+111

  • @sandeepvk
    @sandeepvk 7 місяців тому

    usless video. First learn english, we can learn pointers later

  • @gabrielgomesmabiala6707
    @gabrielgomesmabiala6707 Рік тому +16

    C is a classic language never get old evergreen thank you once more FFC

    • @SS-jq6mh
      @SS-jq6mh Рік тому +10

      FreeFodeCamp

    • @iGhostr
      @iGhostr Рік тому +1

      @@SS-jq6mhlmao 💀

  • @yuliefelice5643
    @yuliefelice5643 Рік тому

  • @nocopyrightgameplaystockvi231
    @nocopyrightgameplaystockvi231 Рік тому +111

    I almost forgot C even had pointers 😂.

  • @samy8124
    @samy8124 Місяць тому +8

    تم بحمد الله، اللهم انفعنا بما علمتنا وزدنا علما.

    • @marbasfpv4639
      @marbasfpv4639 Місяць тому

      Lol what does any of this have to do anything with some god??

    • @samy8124
      @samy8124 Місяць тому +1

      @@marbasfpv4639 you got to thank God for the blessings he gave you like the ability to understand a complex subject such as pointers. my comment was to mark that i have already watched this so i dont forget and watch it again in the future.

    • @zeyadmohamed9935
      @zeyadmohamed9935 22 дні тому

      @@marbasfpv4639 ولو كره الكافرون

  • @NobleAbsinthe
    @NobleAbsinthe Рік тому +4

    I’m at 30 mins so far. So basically we just have to use the & sign when we pass variables in as arguments, and in our functions we use * to declare a pointer and deref inside the function. This way we can actually change the value of our original variable. Is that right?

  • @juanmanuelfuentes314
    @juanmanuelfuentes314 Рік тому +35

    As a computer science engineer I can see how understanding pointers pavement you to understand the underneath meaning of variables, arrays and complex structures. That's something that we all are forgetting with 'modern' languages.

  • @HamletAvetyan-ns6wx
    @HamletAvetyan-ns6wx 2 місяці тому +1

    This ma mannn right here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! thx a lot cuh ))))))))))

  • @squid13579
    @squid13579 Рік тому +4

    Long live C 🔥

  • @874D8
    @874D8 Рік тому +9

    I loved it! I sat down and typed the whole thing and every exercise and this helped a lot. The explanations and examples are really good, I learned a lot even if I thought I was not a total beginner. :)

  • @maejshbrail2233
    @maejshbrail2233 10 місяців тому +1

    Sadly watching this on a phone is basically impossible because of the images and color use. Guess it gottta be on a pc screen

  • @buddikagunawardena2200
    @buddikagunawardena2200 Рік тому +32

    The first 40 minutes was all it took for me to understand this concept of pointers clearly.
    Great Tutorial!

    • @Abdallah..................
      @Abdallah.................. 7 місяців тому

      The same. I understand this concept after watching the first 40 minutes of the video

  • @techdoctorP
    @techdoctorP Рік тому +2

    Can someone please explain how he got 0100 at 1:08:45

  • @dace9294
    @dace9294 8 місяців тому +2

    I appreciate your work thank you so much for your video

  • @lorenne928
    @lorenne928 Рік тому +2

    thank for these pointers, Goodç7

  • @SerralheriaDicas
    @SerralheriaDicas Рік тому +1

    O tema me interessa muito, mas o meu ingles é muito pobre - The topic interests me a lot, but my English is very poor

  • @Ak4n0
    @Ak4n0 Рік тому +5

    Todavía no he visto el video pero en las explicaciones de pasar arrays a las funciones te ha faltado el caso del array de más de una dimensión, que en este caso sí hay que pasarle todas las dimensiones menso la primera a fin de que cuándo se haga uso del array dentro de la función éste sepa dónde buscar el dato. Por ejemplo:
    void (int my_array[][2], sizeof_t size) { ... }

    • @onaecO
      @onaecO Рік тому +1

      Dear friend, you are totally right. The thing is that i thought about super beginners in this video-course. I rarely use 2D matrixes in real life, furthermore i don't wanna scare too much with too many details. This concept i'd say is for more advanced users. Here i just want to bring someone from 0 to 1 with pointers.

  • @theprince_101
    @theprince_101 Рік тому +4

    I just spent today reading chapter 5 of K & R's C programming and this video came 😂....such a weird coincidence

    • @_powerbeard
      @_powerbeard Рік тому +3

      Best language book and it's not even close. Although Borland Turbo C Bible was useful.

    • @CabernetKing
      @CabernetKing 8 місяців тому

      Idk how you got through K&R that book is absolutely atrocious

  • @sabuein
    @sabuein Рік тому +2

    Thank you.

  • @rezamn1362
    @rezamn1362 Рік тому +1

    Thanks guys will you arrange a session about crack games/softwares?

  • @JackHotail
    @JackHotail Рік тому +2

    that course is something different and and an amazing course i hopefully could finish it as soon as possible and thanks freecodecamp

  • @umutaydn6184
    @umutaydn6184 Рік тому +1

    Does stack grow top to bottom or bottom to top ???? Chatgpt says that it grows from bottom to top .

    • @tesfalemeshetu4675
      @tesfalemeshetu4675 7 місяців тому

      Top to bottom for stacks , and bottom up for heaps

  • @sammytiel
    @sammytiel Рік тому +5

    Over 2 hours on just pointers? Now I know why C programmers hate them so much.

    • @_powerbeard
      @_powerbeard Рік тому

      I never hated them, but on the Unix side we had core dumps and you could rebuild the program at point of crash.

  • @rasit5820
    @rasit5820 Рік тому +1

    Thank you for the lesson, but the fonts and shapes used in the education materials are very poor.

  • @phantom_vasploit
    @phantom_vasploit 2 місяці тому +1

    I loved this! I finally understood the pointer concept. Thank you for this.

  • @IanoNjuguna
    @IanoNjuguna Рік тому +1

    This tutorial just dropped at the right time.

  • @adriatic123
    @adriatic123 8 місяців тому +1

    I wish the author uses emglish phrasing im a more standardized way. It would be more clear what he wanted to explain.

  • @sihemmansour5303
    @sihemmansour5303 Рік тому +1

    Good tutorial but why you don't activate subtitle cc

  • @CarCinCal
    @CarCinCal 11 місяців тому +2

    So anyway this is the best C Tutorial on UA-cam…. Well Done!!! 👏🏽 👏🏽 👏🏽

  • @RolandElvira-l4y
    @RolandElvira-l4y 8 днів тому

    Miller Kenneth Taylor Karen Thompson Ruth

  • @GLW-ui9mu
    @GLW-ui9mu Місяць тому +1

    i knew pretty much all of this but watched it anyways because why tf not

  • @enesbicakEEE
    @enesbicakEEE Рік тому +1

    i have finished c exam yesterday and saw this video today :(

  • @OConnorCarr-b7l
    @OConnorCarr-b7l 7 днів тому

    Lopez Carol Davis James Thompson Sharon

  • @veplexer3480
    @veplexer3480 3 місяці тому +1

    As someone who learned pointers at university, I found the video really useful, especially the introduction about computer memory.
    In my opinion, it's not really dedicated to "Absolute Beginners".
    Thanks for your efforts.

  • @hugo-garcia
    @hugo-garcia Рік тому +2

    Can someone explain to me what is const pointers? Is very common to see functions with const pointers as input

    • @eduardof.vicentini9225
      @eduardof.vicentini9225 Рік тому

      Can we have some examples of these functions, please?

    • @hugo-garcia
      @hugo-garcia Рік тому

      @@eduardof.vicentini9225 void func (const int* p){
      // do stuff;
      }

    • @vonderklaas
      @vonderklaas 10 місяців тому

      Guys, GPT is out!

    • @DenisTrebushnikov
      @DenisTrebushnikov 7 місяців тому

      I guess you already found the answer, however I try to explain for myself: any pointer as well as any variable has an address in memory cell, the value in the memory cell can be changed... adding word const we deny changing value. So const pointer that link to address can't be changed, you can't assign pointer a new address. (pointer on const value is the different thing - and this means, that with pointer you can't change value by address)

  • @adebiyiadekunle871
    @adebiyiadekunle871 Рік тому +1

    I want to learn software engineering on UA-cam, can I get recommendations and scheme for this?

  • @surajkumarsingh4857
    @surajkumarsingh4857 Рік тому +2

    Informative ❤❤❤

  • @yousefali-wy7nm
    @yousefali-wy7nm 23 дні тому

    what is the compiler name and version does he use?

  • @JulietCharlotte-y5c
    @JulietCharlotte-y5c 10 днів тому

    Lee Donna Thomas Maria Johnson Frank

  • @petrosstyle2981
    @petrosstyle2981 Рік тому +1

    sorry after the first 40 minutes, it is difficult for a beginner to understand anything.

    • @smallSphere69
      @smallSphere69 Рік тому

      Learn c language first. (Not only basic but also intermediate)
      Then you'll understand.

    • @petrosstyle2981
      @petrosstyle2981 Рік тому

      @@smallSphere69 it says for absolute beginners on the title

    • @smallSphere69
      @smallSphere69 Рік тому

      @@petrosstyle2981 title is kinda misleading

  • @adsfwef1331
    @adsfwef1331 Рік тому +1

    This is very helpful thanks.

  • @rafaelojeda
    @rafaelojeda Рік тому +1

    2 hours of lectures about pointers? Most videos are like 5 mins and I feel that they do not help at all this is great!

  • @soumadip_banerjee
    @soumadip_banerjee Рік тому +1

    Yes 🎉 1st

  • @amund8821
    @amund8821 11 місяців тому +1

    Grazie

  • @vicsteiner
    @vicsteiner 4 місяці тому

    Again thanks for the video. By the end there is this example using vmmap, I understand vmmap is only for mac. Is there a similar tool I can use on a Ubuntu machine?

  • @EMAGK
    @EMAGK Рік тому +1

    data strcture in c please