Arrays are Pointers | C++ For Java Devs Ep. 9

Sdílet
Vložit
  • čas přidán 17. 05. 2024
  • Join the Discord: / discord
    In this episode I talk about how pointers and arrays are similar. I begin by showing how everything in C++ is just a block of memory, arrays are blocks of memory, pointers are blocks of memory, and variables are blocks of memory. Then I show how you can use this knowledge to treat arrays as pointers and vice versa. Finally I show the danger of C++ by setting a separate variable unintentionally by accessing an out of bounds index in an array.
    0:00 In This Episode
    1:01 Note About Deleting
    2:30 Arrays and Pointers (Drawing)
    7:35 Stack vs Heap (Static Allocation)
    8:50 Coding Dynamic Arrays
    12:14 Vectors and Functions
    16:44 Array Out of Bounds (No Error...)
    17:18 Horrible No Good Bugs
    19:57 Challenge! (And nullptr)
    ---------------------------------------------------------------------
    Website: ambrosiogabe.github.io/
    Github: github.com/ambrosiogabe
    Here are some books I recommend if you want to learn about game engine development more thoroughly. I do not profit off any of these sales, these are just some books that have helped me out :)
    My Recommended Game Engine Books:
    Game Engine Architecture: www.gameenginebook.com/
    Game Physics Cookbook (Read this before the next physics book): www.amazon.com/Game-Physics-C...
    Game Physics (Ian Millington): www.amazon.com/Game-Physics-E...
    Game Programming Patterns (Free): gameprogrammingpatterns.com/
    My Recommended Beginning Game Programming Books:
    JavaScript Game Design: www.apress.com/gp/book/978143...
    My Recommended Java Books:
    Data Structures/Algorithms: www.amazon.com/Data-Structure...
    LWJGL (Free, but I haven't read this thoroughly): lwjglgamedev.gitbooks.io/3d-g...

Komentáře • 18

  • @hilbert_curve3680
    @hilbert_curve3680 Před 3 lety

    Oh you answered my question, thanks.

  • @luandkg
    @luandkg Před 3 lety

    👏🏼👏🏼👏🏼👏🏼

    • @GamesWithGabe
      @GamesWithGabe  Před 3 lety +1

      Thanks Luan! I'm glad to see you're still around :)

  • @mightycoderx
    @mightycoderx Před 2 lety +2

    Wait it's just me or you've missed an episode? Because the challenge at the beginning is not what you left us with in episode 8 it's completely different!

    • @GamesWithGabe
      @GamesWithGabe  Před 2 lety +1

      Whoops! It looks like I forgot to add episode 8 to the playlist. It should be in the playlist as well now :)

  • @mrmaniac9905
    @mrmaniac9905 Před 3 lety +1

    Gabe I cannot say this enough. If you like java, you will LOVE kotlin. It is the best language to ever grace God's green earth. Dedicate a week or two, to learning it and I promise you, you'll never be able to look at java the same it'll just be like an annoying little brother.

    • @mrmaniac9905
      @mrmaniac9905 Před 3 lety

      I know you already know java, so kotlin will be a breeze, please take my word for it and stick with it. My game engine is being written in kotlin and it's so freaking nice. You can literally add methods to ANY class, like you could add a method to ALL Strings thats could say split the string in half (just an example idk), the point is kotlin feels so natural once you use it, it's like that saying once you go black you never go back (excuse the crude humor)

  • @sadmansakibkhan8667
    @sadmansakibkhan8667 Před 3 lety +2

    please please continue the game engine series

    • @GamesWithGabe
      @GamesWithGabe  Před 3 lety

      Keep an eye out either later today or tomorrow ;)

  • @elturco9573
    @elturco9573 Před 2 lety

    Es triste porque, creer que un array es lo mismo que un puntero es uno de los mayores errores de personas que llegan a C/C++, y esto fomenta aún mas la confusión. Son tipos distintos y mezclarlos sin cuidado puede causar errores difíciles de detectar, como obtener un tamaño inesperado al intentar hacer sizeof() a un array que "decayo" en un puntero luego de pasarlo a una función (por ej.), o intentar hacer aritmética con el (lo cual no está permitido). Pasar a una función que espera un (char*) un (&array) de hecho es pasar otro tipo totalmente distinto, en concreto ((array*)[N]), y un buen compilador te lo advertirá, lo correcto es pasar (&array[0]) o directamente (array). El operador (*) tampoco funciona con arrays. Por lo tanto, son muy distintos.

    • @GamesWithGabe
      @GamesWithGabe  Před 2 lety +2

      Hi elturco, I agree that this could confuse beginner programmers and this was an aspect I didn't think of when making this video. When I was beginning C++ however, what confused me more than what you mentioned was pointer arithmetic (I actually never encountered any bugs related to what you mentioned). Therefore, I felt like it was important to place an emphasis on how all memory blocks in C++ are just memory blocks. Pointers and dynamic memory allocation and pointer arithmetic always felt like a black box to me and I'm trying to create an illustration that will help programmers with prior experience in different languages understand what is happening when you use dynamic memory allocation.
      Ultimately, I feel like no matter how you teach C++ you are going to miss some idiosyncrasies of the C++ language and the person you are trying to teach will have to learn about this through experience. When I learned C++ I felt like there were no good tutorials out there that taught C++ to somebody who is an experienced programmer in a different language. So I'm trying to change that. I would love to see the community produce more high quality videos teaching C++ to programmers that are experienced in other languages. I'm sure there are much more qualified teachers than me and I hope they start producing this content as well.

  • @mladennikolic4394
    @mladennikolic4394 Před 3 lety

    Continue game engine series pls 🙏🙏

    • @GamesWithGabe
      @GamesWithGabe  Před 3 lety +1

      Keep an eye out tomorrow, or possibly later today ;)

  • @buggybaka
    @buggybaka Před 3 lety +1

    Bro you were the only good java youtuber but you turned to c++ 😭🥺, and you stopped replying my comments cause you are too famous too remember I guess

    • @GamesWithGabe
      @GamesWithGabe  Před 3 lety

      Hey CGO Clan, not forgetting to remember lol. It's just hard to balance a full-time job, hobbies, friends, family and YT. I try to respond to comments at least once a week though :). And keep an eye for another game engine series episode today or tommorow ;)

    • @buggybaka
      @buggybaka Před 3 lety

      @@GamesWithGabe OHHHHH A spoiler for a brand new series ahh? POG

    • @buggybaka
      @buggybaka Před 3 lety

      Might be a huge request but you are good at explaining so please can you make a series for an advanced physics engine in java? It could be a sub series for the java game engine series.

    • @GamesWithGabe
      @GamesWithGabe  Před 3 lety

      @@buggybaka I might have misspoken up there a bit haha. I'll be releasing a new episode for the game engine series that's already there :). And I tried a physics engine in Java already and it didn't go very well because I still don't understand physics good enough, I'll have to revisit a physics series in the future once I understand it better