如何初始化二维数组
2015-08-04 00:12
225 查看
If your 2D array has static storage duration, then it is default-initialized to zero, i.e., all members of the array are set to zero.If the 2D array has automatic storage duration, then you can use an array initializer list to set all members to zero.
set all bytes to zero.
int arr[10][20] = {0}; // easier way // this does the same memset(arr, 0, sizeof arr);If you allocate your array dynamically, then you can use
memsetto
set all bytes to zero.
int *arr = malloc((10*20) * (sizeof *arr)); // check arr for NULL // arr --> pointer to the buffer to be set to 0 // 0 --> value the bytes should be set to // (10*20*) * (sizeof *arr) --> number of bytes to be set memset(arr, 0, (10*20*) * (sizeof *arr));
相关文章推荐
- Android应用架构
- C#Lambda表达式学习日记
- maven的web工程下用pom引入jdbc包,运行时仍显示classnotfoundexception方法
- Git使用遇到的问题--merge冲突解决
- 数据结构与算法1
- UISegmentControl
- hbase 列族优化 ,shell 管理集群
- c++11移动语义右值引用
- JAVA中转义字符:
- 79. Word Search
- LeetCode——Valid Anagram
- Spring + iBATIS完整示例
- 黑马程序员_Java基础:集合总结
- 小练习:用socket实现Linux和Windows之间的通信
- 把握财富第六波
- 自己研究的有关推箱子的--接近完美的代码
- cpu中纵横交错的电路是怎么实现算数的?
- LeetCode239 Sliding Window Maximum
- 【LeetCode】190 & 191 - Reverse Bits & Number of 1 Bits
- volley学习笔记(五):Android Volley框架的几种post提交请求方式