+ 1
[SOLVED] C++ array
How can I create an array in C++, if i have an int variable and I need that it become a length of my new array. int x[intvar] doesn't work.
9 Respostas
+ 5
No buddy, I did understand your question. If you see example in the last slide, you will see that you can improvise from it, by changing the use of literal (20) by the use of a variable for defining number of array's element.
int elements = 20;
int *p = new int[ elements ]; // allocate memory
// Do whatever you want here
delete [] p; // free alocated memory
+ 2
Look at the last slide here
https://www.sololearn.com/learn/CPlusPlus/1632/?ref=app
+ 2
I hope this link helps you.
https://code.sololearn.com/cHwwXMcmj8c0
+ 1
Ipang, maybe you don't understand me, I need to create an array, which length is stored in a variable
+ 1
Ipang, sorry, i don't understand you. Thank you
+ 1
Kind_Cat,
Sorry too, but Idk how to explain it better than the tutorial.
+ 1
RTB, please, read my question to the end. I wrote, that this doesn't work
0
Abhishek Pandey, i wrote that this does not work
- 1
Use this
int var ;
cin>>var;
int arr[var] ;