用0填充多维数组元素 [英] Fill multidimensional array elements with 0's

查看:169
本文介绍了用0填充多维数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个2d,我想将元素设置为零,而不循环所有的元素

I have a 2d and i want to set the elements to zero without looping all the elements

int a[100][200];

我无法在声明点初始化。

I can't initialize them at point of declaration.

推荐答案

尝试

int a[100][200] = {{0}};

如果初始化一些(但不是全部)元素,其余的将初始化为零。在这里,你只是明确地初始化第一个子数组的第一个元素,编译器正在处理其余的。

If you initialize some (but not all) of the elements, the rest will be initialized to zero. Here, you are only explicitly initializing the first element of the first sub-array and the compiler is taking care of the rest.

这篇关于用0填充多维数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆