0

I am learning Data Structures from Schaum's Outlines Data Structures book, and a paragraph says.

On the other hand, some programming languages allow one to read an integer n and then declare an array with n elements; such programming languages are said to allocate memory dynamically.

Please answer the commented question in the following program written in c++.

#include<iostream>

int main(){
    
    int n;

    std::cin >> n;   // reading at runtime.  step1.

    int *arr1 = new int[n];  // I know it is meant for dynamic allocation.  step2.

    int arr2[n];    // Is this dynamic allocation? As reading input at runtime
                    // and creating the array of size correspond to the input taken in step1

    return 0;
}
dukeforever
  • 298
  • 1
  • 7
  • The search term here would be "variable length arrays". I'm looking for a question on StackOverflow that would explain the concept (rather than why it is a bad idea), but I can't find anything... Anyway, they are not a part of C++ standard, some compilers support them as extension. – Yksisarvinen Dec 18 '20 at 07:06
  • @Yakk-AdamNevraumont May you be a bit more explicit about the meaning of your comment, I know this question is little awkward, But, I was just confused when I saw this in the textbook. – dukeforever Dec 18 '20 at 07:12
  • Anyway, thank you @Yksisarvinen – dukeforever Dec 18 '20 at 07:13
  • The duplicate I propose explains that VLAs are not part of C++, has a link on what they are and explains why ("sometimes") code using them does still compile. Please include the things said in the question into your search for an answer. – Yunnosch Dec 18 '20 at 07:19
  • Well, it was an honest question to ask you. **Is an egg a bird?** If you can find a definitive, universal answer to my question, then we can answer the question "is this dynamic memory allocation". – Yakk - Adam Nevraumont Dec 18 '20 at 15:47

0 Answers0