Why is C++ more picky than other language on making an array from a variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is C++ more picky than other language on making an array from a variable?

Java Int x = 5; Int[] y = new int[x]; ✓ all good C++ Int x= 5; Int y[x]; Nope Even if x is a constant going through a method C++ is picky about it Const int x = 5 Method(x); } Method ( const int x){ Int y[x]; } Again it hates that

10th Sep 2019, 11:50 PM
Stuart Moss
Stuart Moss - avatar
3 Answers
+ 3
Author seems to compare dynamical array in java with constant array in cpp? But there are many ways to make dynamical array in c or cpp: malloc & realloc in c, instruction new in cpp or even STL vector. So, what's the problem?)
11th Sep 2019, 7:11 PM
Dmitrii
+ 2
good
11th Sep 2019, 7:40 AM
محمد عبدالله ابوعمود
محمد عبدالله ابوعمود - avatar
+ 1
Ace thanks, it makes alot of sense now
11th Sep 2019, 1:00 AM
Stuart Moss
Stuart Moss - avatar