ques-https://hack.codingblocks.com/app/practice/6/1044/problem
code-https://ide.codingblocks.com/s/379708
sir in this ques or rather any other ques concerning arrays what should be the ideal size of the array that we declare .
in this ques at first i had declared the array as arr[1000] and it failed one of the testcases
DOUBT-search a num
hello @aaliyah_beg
u dont have to guess the size of array.
u should always declare array like this->
int n;
cin>>n; // first read size of array and then declare array
int a[n] ; // declaring array of size n
sir, but a variable size for an array is not allowed and the size of an array should be static, isnt it?
in dynamic allocation u can change the array size as well(by erasing and allocating new memory check vector implementation for clarity).
yeah array size will be fixed in case of static allocation.
the code that i shared above will work always.
and it neither comes under static allocation nor dynamic , some people say it a pseudo static allocation becuase declarition is compile time but the size will be determined at runtime.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.