[Beginner]Variable length arrays
helxi via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Feb 25 06:31:49 PST 2017
I am trying to create an array which has a user defined size.
However the following program is not compiling:
import std.stdio;
void main(){
write("Enter your array size: ");
int n;
readf(" %s", &n);
int[n] arr; //<-Error: variable input cannot be read at
compile time
writeln(arr);
}
1. What's causing this?
2. How can I get around this? I know I can always create a loop
that appends value 'n' times.
More information about the Digitalmars-d-learn
mailing list