memset的 [英] memset
本文介绍了memset的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么要使用memset以及memset是什么(a,0,sizeof(a));代表?可以通过一些例子让我清楚地知道吗?谢谢..
解决方案
为什么要使用memset和memset是什么(a,0,sizeof(a));代表?有些人可以通过一些例子让我清楚地知道吗?谢谢..
如果你要在分配内存之后声明一个数组以二次方式...通过使用malloc或calloc ...你可以使用memset函数用null初始化数组的元素....
(a,0,sizeof(a ));
它是一个数组,你将使用null来启动元素....
例如
展开 | 选择 | Wrap | 行号
The Stand ard C库函数 memset()(在< cstring> 中)用于方便....它设置从特定地址开始的所有内存(第一个参数)在起始地址之后 n 字节的特定值(第二个参数)( n 是第三个参数)。当然,您可以简单地使用一个循环来遍历所有内存,但 memset()可用,经过充分测试(所以它不太可能会引入错误),以及可能比你手工编写它更有效。
来自Thinking in c ++
感谢所有的回复
why use memset and what does memset(a,0,sizeof(a)); represents?can some one make me clear abt memset with some examples?thanks..
解决方案why use memset and what does memset(a,0,sizeof(a)); represents?can some one make me clear abt memset with some examples?thanks..
If you are going to declare say a array dianamically.... after allocating memory by using malloc or calloc... U can use the memset function to intialise the elements of array with null....
(a,0,sizeof(a));
It syas that a is array and you are going to initailse the elements with null....
For example
Expand|Select|Wrap|Line Numbers
"The Standard C library function memset( ) (in <cstring>) is used for convenience .... It sets all memory starting at a particular address (the first argument) to a particular value (the second argument) for n bytes past the starting address (n is the third argument). Of course, you could have simply used a loop to iterate through all the memory, but memset( ) is available, well-tested (so it?s less likely you?ll introduce an error), and probably more efficient than if you coded it by hand."
From Thinking in c++
thanks for all the replies
这篇关于memset的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录 关闭
扫码关注1秒登录
![](https://huajiakeji.com/Content/Images/qrydx.jpg)
发送“验证码”获取
|
15天全站免登陆