How to define a const array first and give its length later in a function?

I direct answer to your question could be

# create an empty Vector{Float64}
A = Float64[]   # this is the same as A = Vector{Float64}()

# change its size to 100
resize!(A, 100) 

# It's now filled with garbage values, that you must overwrite 

It is possible that you are coming at the problem from the wrong angle. You don’t generally need to ‘declare’ variables in dynamic languages such as Julia, so you could just wait to create A until you know the size you want.

6 Likes