C++ Dynamic Arrays (Dynamically Allocated Array)

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ก.พ. 2025
  • C++ Dynamically Allocated Array. More often referred to as a dynamic array, although this is incorrect since dynamic array refers to another concept, but we will discuss that in another video. In this video you will learn how to allocate an array on the heap. This is referred to as a dynamically allocated array, which defers from a statically allocated array on the stack. By creating an array on the heap, the array capacity does not need to be determined at compile time. For this reason, we can create an array that can have varying sizes.
    If you need to review these topics:
    Arrays: • Arrays in C++
    Pointers: • Pointers in C++
    Pointers to Arrays/ Pointer Arithmetic: • C++ Pointers and Arrays
    Null Pointers: • C++ Null Pointers
    Dynamic Memory Allocation: • Dynamic Memory Allocat...
    C++ Playlist:
    • C++ Tutorial
    Install C++ with VS Code:
    • How to set up C++ in V...
    Subscribe for more coding tutorials 😄!

ความคิดเห็น • 10

  • @tomlam2885
    @tomlam2885 หลายเดือนก่อน

    Thank you so much! Finally understand what is dynamic array🎉

  • @MSaad-ek6js
    @MSaad-ek6js 12 วันที่ผ่านมา

    Summary or bullet points:
    1) In C++, for stack we should use constant size for array while in heap allocation size can vary based on user input.
    2) int lottery_tickets[size ] ; is same as int * lottery_tickets = new int[size];
    3) lottery_tickets[i]; is same as *(lottery_ticktets + i )

  • @yousefebid2765
    @yousefebid2765 8 หลายเดือนก่อน +5

    thank you bro

  • @nehaltalapalli8959
    @nehaltalapalli8959 13 วันที่ผ่านมา

    what if even the user doesn't know how many items they want to input? Like in the scenario of a shopping list where the user remembers stuff they need to buy as they write the list. Great video regardless, you have earned a like from me.

    • @KennyYipCoding
      @KennyYipCoding  3 วันที่ผ่านมา

      then you would use a vector!
      a vector utilizes an array allocated on the heap already. See my next video (C++ Dynamic Arrays vs Dynamically Allocated Arrays) to learn how this actually works: th-cam.com/video/6luxAZrZbJc/w-d-xo.html

  • @Viktor-mk4sl
    @Viktor-mk4sl 6 หลายเดือนก่อน +4

    Great video, thanks for explaining it well. On a sidenote, what keyboard/switches do you have? They sound amazing

    • @KennyYipCoding
      @KennyYipCoding  5 หลายเดือนก่อน

      Thanks! The exact keyboard I'm using is:
      Keychron K5 SE Wireless Mechanical Keyboard
      White Backlight / Low Profile Gateron Mechanical / Brown

    • @Viktor-mk4sl
      @Viktor-mk4sl 5 หลายเดือนก่อน

      @@KennyYipCoding Thank you!

  • @OmerElballa
    @OmerElballa 6 หลายเดือนก่อน +1

    What keyboard do you have? It sounds amazing!!

    • @KennyYipCoding
      @KennyYipCoding  5 หลายเดือนก่อน +2

      Thanks! The exact keyboard I'm using is:
      Keychron K5 SE Wireless Mechanical Keyboard
      White Backlight / Low Profile Gateron Mechanical / Brown