0

Can i take the size of array from user in c++??

there is no description

5th Feb 2020, 12:38 PM
alaa ebrahim
alaa ebrahim - avatar
7 ответов
+ 4
alaa ebrahim How you could say that this maybe best answer if there is no more answers.
5th Feb 2020, 1:06 PM
A͢J
A͢J - avatar
+ 2
int n; cin>>n; int array[n]; This way is possible.... Hoping this is what you searching... Edit: For additional info regarding this, see the post of @shadow sir/mam post below..
5th Feb 2020, 12:47 PM
Jayakrishna 🇮🇳
+ 2
I would just like to mention that the code int n; cin >> n; int array[ n ]; is not exactly standardized C++. Variable-length arrays are a part of C as of C99, but haven't been introduced to the C++ standard. Most compilers will support the construct as a language extension, but I don't think you should rely on this. The "proper" way would be to either use dynamic memory allocation: https://www.sololearn.com/learn/CPlusPlus/1632/ Or just to use std::vector: https://en.cppreference.com/w/cpp/container/vector
5th Feb 2020, 1:12 PM
Shadow
Shadow - avatar
+ 1
Shadow Is there any wrong or changes needed to my answer..? Please tell me, if there any.. I just said as " a possible way" since he asked about array type(static).. To don't miss lead any one, correct me if there any wrong.. And Thanks for the addition information...
5th Feb 2020, 1:31 PM
Jayakrishna 🇮🇳
0
I know this answer but i want to make sure that this is a good answer
5th Feb 2020, 1:00 PM
alaa ebrahim
alaa ebrahim - avatar
0
Was a wrong from me
5th Feb 2020, 1:07 PM
alaa ebrahim
alaa ebrahim - avatar
0
Jayakrishna Nothing besides what I have already mentioned. Just wanted to point out that it, although working, is not pure standard C++, and therefore should be avoided from my perspective, that's all.
5th Feb 2020, 2:17 PM
Shadow
Shadow - avatar