Yes. As you can not initialize a variable before knowing its content, your code is the best and correct way for allocating the array.