Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialization of a large const array?

Tags:

c++

arrays

c

Are there anyway to initialize a large const array without typing every single elements within it, for instance:

trying to create a array:

const double A[1000] = {1.0/1, 1.0/2, 1.0/3,...,1.0/1000};

It's easy to do with a loop.

like image 296
user2003564 Avatar asked Jan 15 '23 10:01

user2003564


1 Answers

If it really has to be const and you have 1000 different values write some kiddy app/script to spit it out as a header file and prevent your typing! That gives you an easy way to modify the whole array initialisation later if need be too.

like image 112
Joe Avatar answered Jan 27 '23 08:01

Joe