Pointers in C

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

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

  • @TheSar
    @TheSar 6 лет назад +252

    I studied C native in University on Solaris and this explanation of pointers is far and away better.
    Better on all fronts. Well done Sir.

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

      This is just the basics, here he is only addressing it... wait until you work with dynamic memory and the heap... I've learned C long ago but I'm more familiar with C++. The basic way to create a block of memory in C++ is with new and new[] and to free them is with delete and delete [] respectively. Today, this is considered bad practice unless you truly know what you are doing and you have a very specific reason for using "raw pointers" as the conventional way is to use std::shared_ptr and std::unique_ptr... In C this is done with malloc() and free() and some other memory-based functions.

  • @Seaprimate
    @Seaprimate 5 лет назад +16

    I feel that despite not having any fancy visuals or elaborate analogies, I feel I intuitively understood more in these 10mins with your video than I did through multiple other longer videos combined. I don't know how you did it but thank you!

  • @SwedishDude08
    @SwedishDude08 4 года назад +80

    To people getting this error message from gcc: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int *’
    Change %x to %p and it will work.

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

      yes, some things have changed with the new C standards in the compiler.

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

      "%d" worked for me

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

    Currently in a college course learning C and this is the only explanation I've heard in class or on the internet that makes pointers make sense. Can't thank you enough.

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

      My pleasure. I hope your courses go well 👍

  • @john_avernia
    @john_avernia 2 года назад +2

    I just started learning programming (several weeks now) and your video really helps me a lot in understanding pointers. Which is, from what I heard, is one of the hardest subject in C programming.

  • @Hunter725R
    @Hunter725R 4 года назад +177

    Me: Visual Studio for C with autocompletion for smallbrain
    Him, a divine being: nano on a Rasperry Pi Zero for C.

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

      @Christian Weissmuller Vim is evil, use emacs instead and enjoy your sprained pinky!

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

      @@SwedishDude08 Well Evil Emacs is kinda nice :D

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

      @Christian Weissmuller vim is for noobs use xemacs!

    • @Andrew-wo8ry
      @Andrew-wo8ry 4 года назад +6

      Notepad++ gang.

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

      you guys still use nano? real men just
      echo "#include int main(){printf("Hello World");}" >> program.c

  • @LoyalSlime
    @LoyalSlime 6 лет назад +301

    sir please do more C tutorials

    • @GaryExplains
      @GaryExplains  6 лет назад +105

      If there is enough interest then I will.

    • @thomasb1337
      @thomasb1337 6 лет назад +7

      I'd love it. I'd even pay for it on something like udemy =.

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

      +1

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

      That would be amazing!

    • @nikhil.n
      @nikhil.n 6 лет назад

      sir we are interested in programming tutorials do make more of them.

  • @skylo706
    @skylo706 4 года назад +75

    Oh I wanted to make a tutorial on pointers myself called "How to SegFault in C"

  • @fifaham
    @fifaham 4 года назад +6

    I have been browsing for tutorials and found many on RUclips for things I already know, I found yours to be one of the best and I will keep your link here with me. Job well done.

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

    Thank you for demystifying pointers for me. They have been a real pain in my neck.

  • @Ejeby
    @Ejeby 2 года назад +7

    4:30 & tells you the address, * tells you the dereferenced value
    6:50 in c an array name is equivalent to its pointer
    7:30 increment the pointer

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

    I'm just in the beginning of getting into C after learning Python. There really is something beautiful about how basic and (relatively) low-level it is.

    • @DrSpooglemon
      @DrSpooglemon 2 года назад +2

      Scared the b'jesus out of me moving from the well ordered metropolis of Python to the wild west of C.

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

    Dude, you're a godsend, I could not understand pointers for the life of me before watching this video

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

    By far the best explanation of pointers I have come across

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

    Now I understand how pointers work, after 4 years of trying. Thanks for explaining, Gary!

  • @D3ND
    @D3ND 6 лет назад +9

    Great video! pointers are definitely one of the more tricky parts of C that I have faced, especially when going for data structures (linked lists, dynamic arrays... ) with allocating and freeing and so on...

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

    I went through so many tutorials just to understand this...Only this single fast-paced video helped me understand... Thank you.
    Please tell me there are more videos like this

  • @eatscaper
    @eatscaper 6 лет назад +3

    Your tutorial in C was superb ! Make more tutorials and gain the attraction of new developers and of course you are great !

  • @felaflame
    @felaflame 5 лет назад +2

    Excellent explanation. Simple, going straight to the point.

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

    Best pointers explanation I've seen!

  • @陈瀚龙
    @陈瀚龙 5 лет назад

    Old guy here. I've been self-teaching Java and soon to start Android, but not sure how to approach learning Android. I decided to take a break and learn some C and explore Linux more in-depth which led me to this video. It was nice to see you using NANO and excited to hear about the Java/Android course. I'll have a look. Great job with this vid, short as it was, good introduction to pointers.

  • @arjunkharbanda
    @arjunkharbanda 6 лет назад +2

    One of the best video on pointers. Please make more such programming videos like Data Structures etc

  • @JesusMartinez-zu3xl
    @JesusMartinez-zu3xl 3 года назад +1

    You literally taught me in 12 minutes! compared to what my professor taught us... Thank you!! also understood you much more better.

  • @ST95953
    @ST95953 6 лет назад +127

    my teacher couldn't explain this properly. Thanks!

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

      Lol

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

      Your teacher tried to explain this? Mine didnt even bother to explain lol

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

      Change your college

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

      Haha same

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

      Read books😔🙏🙄its not even a hard concept to grasp

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

    I didn't learn anything new about pointers, but boy oh boy I had no clue some shells supported the exclamation point notation for repeating previous commands, that makes me excited.

  • @aliftaufik1934
    @aliftaufik1934 6 лет назад +62

    The question is why should we prefer using pointer rather than using, for instance, the index number of array to loop it??

    • @danielgysi5729
      @danielgysi5729 5 лет назад +36

      This is what I hoped this video would explain. Unfortunately I'm left feeling more confused than when I began

    • @SamChaneyProductions
      @SamChaneyProductions 5 лет назад +64

      Pointers allow you to change the value of multiple variables from inside a function, and they even allow you to pass functions as arguments into other functions, both of which are impossible without them.

    • @RadicalEagle
      @RadicalEagle 5 лет назад +11

      @@SamChaneyProductions thank you! As someone who is not familiar with C I couldn't quite understand why this was important.

    • @reiniertl
      @reiniertl 5 лет назад +10

      There is a very interesting advantage but I really don't recommend it unless you really need the most performance.
      When you use array indexing in a loop the compiler (in theory) generates code to bring into the CPU registers the base address of the array and the value of the index, then it must compute the address you want to get access to. So you need two read access and a sum (all this is in machine code so it is very architecture dependent).
      When you use a pointer to access the elements of the array and you are traversing the array in a fixed pattern you can take advantage of pointer arithmetic, since you are incrementing the address by a fixed number the compiler generates code to bring the address value to the CPU register and the increment will be put into the ADD instruction code, so you save at least one instruction per access (no need to fetch the index value from memory).
      For example, the code bellow shows the differences:
      #include
      int array[10]={100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
      int main(){
      //This is a bit slower but more clear
      int val;
      for (int i = 0; i

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

      Better to use pointer when, for example, you don't know what the array size will be at the beginning. Let's take a text file which has to be parsed and values stored.
      First, you do a malloc which gives you a pointer and begin to read the text file. Then, if you haven't allocate enough memory, you can do a realloc and continue to read and parse the file.

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

    Been a while since you shared this, but a better explanation than my professor at uni explaining c++ pointers. Cheers.

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

    That sign behind you terrifies me, fully understanding what that will do. Happy debugging!

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

      Why should that terrify you?

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

      Here is a little C program using the code on the signpost!
      #include
      int main() {
      int **ptr;
      int *ptr2;
      int x=42;
      ptr = &ptr2;
      *ptr = &x;
      printf("x is %d
      ", **ptr);
      return 0;
      }

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

    this is the best explanation ive come across so thank u for this. i am curious as to what the point of pointers are. to fill the array u also could have just referenced each index as well

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

      If you had a large Image that you want to process in a function, should you pass the whole 5MB to the function or just a pointer? They are also useful for many types of data structures, see my video on linked lists.

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

    Best explaination I have ever seen

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

    Thank you Sir, subscribed in 2021, all the very very best from Romania :)

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

    Gary mate you’re a legend

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

    It dawned on me as you were typing (3:11) *aptr = &x because in a variable "aptr" you literally store the (hex)value of the address of an "x", which is nothing else than &x. No more, no less. The only thing that confuses me a bit is that doing "pointer arithmetics" decimal number is added to hexadecimal...

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

      Decimal and hexadecimal are just ways we represent numbers for humans. The numbers are the same. Adding 15 to something and adding 0xF are the same thing.

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

    missed that part at school because of the covid , had trouble with the array part. Thanks for the video. Aannd subscribed

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

    The star (*) is called the indirect operator because it access indirectly the value of a variable through the pointer.

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

    *GARY!!!*
    *Good Morning Professor!*
    Great video as always!

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

    you have taught pointer better in 10 min than my professor has in 3 hours

  • @nagesh007
    @nagesh007 6 лет назад +15

    Thanks a lot , can you please teach " C structures and unions" ?

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

      It's easy 🙄🙄, I hope you have learned till now 🤣🤣

  • @JP-nj2sl
    @JP-nj2sl 5 лет назад

    Very clear explanation of pointers

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

    Thank you! You explained pointers really well

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

    Your main function should return a value. Other declare it void. Good explanation! Very clear.

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

      LOL, not the grammar police, but the code review police. 😂

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

    This was so incredibly helpful! Thank you!

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

    Big ups for Nano. Big ups for good display colors.
    Salutations, friend.

  • @filker0
    @filker0 5 лет назад +3

    There's so much more that can be covered with respect to pointers. Passing by reference, linked lists, dynamic allocation, struct pointers, function pointers, and using pointers with array syntax. Also, sizeof(ptr) vs sizeof(*ptr). Understanding pointers is essential to sophisticated C programming, and correct use of pointers is essential for robust and bug free code.

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

      Yes, of course. This is an introduction video.

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

    Sir, please do more videos on more C concepts.

  • @Abdulrahman-uk9ny
    @Abdulrahman-uk9ny 6 лет назад

    Thanks a lot for the very good explanation. I am about to enter the final exam of C in college... I didn't understand the language well, but I may pass the exam... I think I need to study the C language again in detail..
    please make a whole tutorial for C language.

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

    commenting four years late but thanks dude this was massively helpful

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

    thanks gary that helped a lot !

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

    Great video Gary.

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

    Thank you so much Sir .. Such crystal clear explanation with demonstration.

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

    Thank you. We need more videos like this.

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

      I will certainly do more programming videos including C and Python. However they aren't the most popular type of video, so I will only be able to do them from time to time.

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

    this video made sense for me and it gave me an idea what a pointer really is to my small brain 😂

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

    please, do more classes like that!I am now subscribed.

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

    Is it possible to make the val of a non-pointer var a mem address and then use the * operator on that normal var to get the val in the mem address that is its val? There must be some way to do that, unless it was architected to not allow that (doubtful)

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

      Why a non-pointer var? I don't see the need or benefit. As a side note, with casting you can convert almost anything. For example:
      #include
      void main() {
      int x = 42;
      long y = (long) &x;
      int *p = (int *) y;
      printf("%d
      ", *p);
      }
      Output:
      42

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

      @@GaryExplains Apologies that I didn't see that reply until today. Thanks for including that nice example code!👍🏻

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

    Great tutorial. Thanks

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

    Thank you this is 30x better than my prof

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

    concise, straight to point, thanks

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

    Thank you very much Gary. Very helpful.

  • @JM-yj4yy
    @JM-yj4yy 4 года назад +1

    has pointer exam in 2 days,
    bless you RUclips algorithm, sweet child

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

    Thank you for the informative video. Is there any benefit to using a pointer to traverse an array vs the traditional way?

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

    I already knew everything, but I still watched the whole video.

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

    Straight from 90's!

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

    Cool logo you have there , and thanks for making this video

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

    well done, really well done. Can you please continue to teach C in such a understandable way.

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

      I am glad you liked it. I will certainly do more C tutorials from time to time, but my only concern is that they don't seem that popular.

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

      i can see that from the views, I feel like there is so little interest in C because it is quite a difficult language to learn, especially as a first language. Its my first language I am learning but only because it's a module i have too finish for my degree . I would personally like to learn python first, love the language and the simplicity. I have learned a lot in this video and used it to do one of my tutorials. I've spent about 3 days now trying to figure out how to assign new values to an array and keep the memory addresses. Then it needs to give the new values for the array and the addressees. Just can't seem to get it right.....
      The fact that the C videos are so unpopular might actually have to do with the fact that no-one is interested in learning it as a first language and because of the immense lack of useful videos on it, which is kind of a vicious cycle.

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

    Understanding pointers was pretty easy from this. What I fail to see is why it is better than just referencing the variable.

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

      If you had a 4MB image and you wanted to apply a filter, would you pass the 4MB variable to the filter function (which means allocating another 4MB and copying the image) and then return another 4MB (with allocation and copy). Or just pass the few bytes needed for the pointer?

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

    Great video! Thank you

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

    Finally, someone explaining what something is.

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

    More c please!!! And c in embedded environment! Thank you Sir!!!!!

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

    That took me back more than 30 years..

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

    Hey Gary, can you do a video on the difference between C and C++ and C#? Thanks for these awesome videos!

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

      Hmmm, that could be an interesting video... thanks for the idea.

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

      @@GaryExplains ❤️❤️❤️❤️ I honestly can't believe you replied

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

    tnx you explain in an interesting and clear way

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

    Dang this guy does a really good job

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

    I was reading about pointers in the acclaimed book "Head First - C" and wasn't understanding a thing. Then, I came across this video and everything made sense. Thank you!

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

    The confusing part is that you use * to tell C that a variable is a pointer. But when you want to save something in this variable you use & to get an adress and * to get a value. I do not understand, why it is not the other way around..

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

    Old memories. Thanks. 😊

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

    Greetings from Brazil!

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

    love your contents here
    can u make a video explaining the digital ciruit realization of how pointer works?

  • @Patrick-xx4kk
    @Patrick-xx4kk 6 лет назад

    Quick but not dirty :> well explained.

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

    it would be nice if you explained why you would want to use a pointer over access by index. Is it more efficient in some way? It looked to require a bit more knowledge to read.
    I never did anything with C before, so the only value I can intuit is that passing a pointer to a function can save copying the value in cases a copy doesn't help.
    It's not clear from the video why you would prefer to deref a pointer over using a variable directly.

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

      Well, why you would use pointers is different to how. This video is how. Check out my video on linked lists for an example of why.

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

    Unrelated question: what's the name of the music you're playing for this video?

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

    Absolute masterpiece

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

    shouldn't printing the address of what pointer holds be with %p and proper type casting?

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

    I'm getting some strange output. I'm getting 5 outputs. The first gives the value 2, then, values of the other array elements (all 0) then the fifth value is the memory location of the last element. Then, it repeats with 2, hen, 4, then zeros, until it prints the memory address of the last location. This happens 5 times until the array has been completely filled. It's weird ..I can't see what could lead to that behaviour,
    Never mind..I had the second for loop enclosed inside the first..that was the problem. It's all good now.

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

    Thank you Gary!

  • @nikhil.n
    @nikhil.n 6 лет назад

    please do make a viddeo talking more about programming and python it really helps.

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

    I've always used vs code, but now um curious on how do you code in the terminal like that

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

    Very well done, thank you very much.

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

    Really helpful, thank you Sir!

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

    brilliant! love how you made this video , thanks :)

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

    Can someone explain the purpose of a pointer, because you can just directly increment the index of the array (somenumbers) to update its values right?
    Instead of using a pointer? Why not call the variable directly??

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

    I really appreciate ur effort

  • @rban123
    @rban123 5 лет назад +2

    Node* root;

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

    Very informative video 👌

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

    Pretty cool. But, what is that primitive program you're using, and primitive OS?
    Is it like a DOS legacy inspired thing for certain people? I need to see my project structure, seriously, all files, etc.

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

      I tell you what I am using at 1:42

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

      Oh, I def heard the pie and nano.
      Is the pie a computer, or OS on a computer, is it a console, terminal?
      Others use Sublime for C so I'm guessing Nano is something required for use on Raspberry Pie?

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

      I heard it, but it doesn't tell me anything. LoL

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

      @@lukenukem8028 It seems you are missing some fundamentals here. I have videos covering just about every question you asked here. The comments section isn't the place for me to fill in the gaps for you.

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

      This is the first video of yours I've seen.
      I'm only asking what R.Pie and Nano are.

  • @רותלוי-ע2צ
    @רותלוי-ע2צ 3 года назад

    Great video!

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

    Subtitle at the beginning: hello my name's Gary simps

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

    How did you get it to compile without return 0;

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

    But i still cant figure out why to use them when we can definitely ignore them and still create a similar program.

    • @GaryExplains
      @GaryExplains  6 лет назад +2

      The power comes when you do more complicated things.

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

    Really love your videos. I have been coding (amateurishly) since 1981 and although I fully understand what pointers are in C, I am still at a loss as to why I would use them over regular variables. Your video clearly shows how a pointer can work just like a variable, but what is the advantage of a pointer?? If today's compilers are very good at their job, they would create the same executable which ever way it was coded, surely? Does using pointers help instruct the compiler how to do their job? make the compiled code faster?? leaner?? is that an issue today? I am sure that there must be some examples of where pointers are essential that normal variables could not work, but maybe that would be too advanced and therefore not covered here? Please, give us an example or two where pointers really come in their own and we can really take advantage of them!! Thanks!

    • @GaryExplains
      @GaryExplains  5 лет назад +3

      Here are two examples of where pointers are useful. 1) Data structures like linked lists. You can manipulate the data structure, and access it, using pointers. Very fast and every efficient. I have a video here: ruclips.net/video/AkB61H15HJw/видео.html 2) Passing information from one function to another. If you have a block of data you don't want to pass the data by value and copy all the data onto the stack or heap, you can just pass a pointer to it. For example if you are manipulating a 6MB jpeg file in memory. You wouldn't pass around the image itself, but rather a pointer to it.

    • @drcl7429
      @drcl7429 5 лет назад +3

      The main reason is higher speed and lower memory - mostly when using functions.
      If you pass a large array to a function, the program must make an entire copy of the array. This requires a lot of CPU time and memory especially if you use that function regularly.
      If you use pointers, you only need to pass the memory address of the original array. No copying required so no excess cpu or memory usage. The trade off is you have to think a bit more and be careful not to reference memory you aren't supposed to.

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

    Great explanation