+ 5

How to define size of an Array at run-time in C++ / Java?

I know that we have to define size of an Array before the run-time using a constant or a number. But, consider a case in which we have to define it on-the-fly then, how could we achieve that. Any ideas?

11th Apr 2018, 3:01 PM
777
777 - avatar
5 odpowiedzi
+ 10
Okay, wrote a simple example for ArrayList: https://code.sololearn.com/cGkFIZqQ4xw3/?ref=app
11th Apr 2018, 6:05 PM
Tashi N
Tashi N - avatar
+ 9
Java: You could use an ArrayList or another list implementation. Simple as that ;)
11th Apr 2018, 3:18 PM
Tashi N
Tashi N - avatar
+ 4
Tashi N, an example would be helpful :) I have just started Java and still covering the basics!
11th Apr 2018, 4:29 PM
777
777 - avatar
+ 2
In C++ you can use the keword "new". You have to access it via pointer: int* arrptr = new int[size]; don't forget to delete it with: delete[ ] arrptr; https://code.sololearn.com/c6b4Dszb2066/?ref=app
11th Apr 2018, 3:49 PM
XiLef
0
what is the difference between println and print?
23rd Apr 2018, 9:06 PM
Look Hook Sook
Look Hook Sook - avatar