如何初始化第二个数组元素是'双数据类型'容易为-1或0

时间:2016-07-15 05:58:10

标签: c++ arrays initialization

我想将双重第二个数组元素初始化为-1或0。

如果是整数,我们可以写如下

int cache[100][100];
memset(cache, -1, 100*100*sizeof(int));

但是如果是double,我怎样才能轻松初始化第二个数组呢?我能处理的最好的方法,但非常难看,低于

double cache[100][100];
for(int i=0; i<100; i++)
   for(int j=0; j<100; j++)
       cache[i][j] = -1;

有人知道这方面的最佳解决方案吗?

1 个答案:

答案 0 :(得分:0)

将数组元素初始化为testdb=# explain (analyze, verbose) SELECT n.name, e.producer FROM products e INNER JOIN products_names n ON n.product_id = e.product_id WHERE n.name ilike '%eda%' limit 20; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=58.34..260.70 rows=20 width=60) (actual time=0.257..0.458 rows=20 loops=1) Output: n.name, e.producer -> Nested Loop (cost=58.34..49564.37 rows=4893 width=60) (actual time=0.256..0.454 rows=20 loops=1) Output: n.name, e.producer -> Bitmap Heap Scan on public.products_names n (cost=57.92..14890.29 rows=4893 width=39) (actual time=0.245..0.333 rows=20 loops=1) Output: n.product_id, n.lang, n.name, n.name2, n.name3, n.products Recheck Cond: ((n.name)::text ~~* '%eda%'::text) Heap Blocks: exact=18 -> Bitmap Index Scan on products_names_name_gin_idx (cost=0.00..56.70 rows=4893 width=0) (actual time=0.160..0.160 rows=797 loops=1) Index Cond: ((n.name)::text ~~* '%eda%'::text) -> Index Scan using products_pkey on public.products e (cost=0.42..7.08 rows=1 width=29) (actual time=0.005..0.006 rows=1 loops=20) Output: e.producer, e.product_id Index Cond: (e.product_id = n.product_id) Planning time: 1.000 ms Execution time: 0.494 ms (15 Zeilen) Zeit: 2,563 ms 很简单。

0

将它们初始化为double cache[100][100] = {}; 并不容易。您必须将整个数组写为:

-1

您可以使用以下方式将其设置为double cache[100][100] = {-1, repeat 10000 times};

-1