0
Can i take the size of array from user in c++??
there is no description
7 Respostas
+ 4
alaa ebrahim How you could say that this maybe best answer if there is no more answers.
+ 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..
+ 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
+ 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...
0
I know this answer but i want to make sure that this is a good answer
0
Was a wrong from me
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.