We create Dynamic Array when we don't know the exact size of input at compile time, right? But can't we solve this problem without using Dynamic arrays? For Example:
cout<<"Enter Size of Array";
cin>>x;
int arr[x];
By using above piece of code we can create an int Array and the Size of Array depends upon User Input (i.e x). If this Code Solves our problem then what is the need of Dynamic Array?
I am new in programming, So try to explain it Simply. Thanks.
For example, We want store the details of the users subscribed to a product updates.
In this case we don't know how many users will subscribe to the product updates. So we will need dynamic arrays or we can use vectors in C++.
Generally in competetive coding we don't need dynamic arrays as we know the input before hand. But in real world use cases we might need the dynamic arrays.
Additional references:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With