Review

C++ POINTERS (2020) – How to create/change arrays at runtime? (Dynamic arrays) PROGRAMMING TUTORIAL

Rate this post



Dynamic arrays are arrays that are allocated at the run time, rather than at compile time. Because of that Dynamic array can change its size during run time.
In this video, I’m explaining the most important differences between arrays and linked lists, demonstrating how to allocate and deallocate memory using “new” and “delete” keywords, and how to create and use dynamic arrays.

We’ll be writing C++ code using Visual Studio 2019 Comunity.
Link for download:

Follow me on other platforms:
Instagram 📸 –
Twitter 🐦-

Tag: dynamic array c++, codebeauty, code beauty, c++, pointers, what are pointers used for, pointers tutorial, for beginners, pointers in c++, easy, programming, course, tutorial, understand pointers, learn pointers fast, uses of pointers in c++, dynamic arrays, how to create array at runtime, allocate, deallocate, commands new and delete, linked list vs array, how to use new and delete, how to allocate dynamic memory, user defines size of the array, how to create dynamic array, what are dynamic arrays

Xem thêm: https://blogthủthuật.vn/category/review

Nguồn: https://blogthủthuật.vn

28 Comments

  1. Why am I able to run my code using a normal array of a size defined by the user? I'm coding in Visual Studio Code. My code looks like this:
    int main()

    {

    int size;

    cin >> size;

    int myArray[size];

    for (int i = 0; i < size; i++)

    {

    cout << "Array[" << i << "]: ";

    cin >> myArray[i];

    };
    It runs just fine but I also know that you cant append or pop items to/from an array like in Python for instance. So why is my code right or wrong?

    Reply
  2. In your first example when you allocate memory for the array. Was that necessary? I tried it without allocating memory with "new int" and the code worked anyway.

    Reply
  3. You told in the tutorial that the integer number of the array must be constant…after watching your video,I tried to do this & I expected that codeblocks will see me a error…..bt it didnt show me any error.I took input from the user & assaigned it to the array,& it runs without creating any problem. How this is possible?I put my code in the comment.Please kindly let me know about this if you see my comment🙂

    Reply
  4. Excellent. I have a question. Why don't we need the zise of array when we delete? How compiler know how many bytes it need to free? Thank you!

    Reply
  5. can you compare some of these concepts and syntax compatible with C? I know since C is not a OOP so one wouldn't expect to see classes there. But concepts like this would be in C as well.. Can you please talk about malloc(), calloc(), free() and realloc(). What is the difference, which one is better in what conditions. etc..

    Reply

Post Comment