memset这个函数的详细,要求有相应的示例代码和说明

来源:百度知道 编辑:UC知道 时间:2024/05/21 07:43:18

void *memset( void *dest, int c, size_t count );
dest是一个地址,c是0-255之间的值,count是要写的字节数。
这个函数的作用就是将dest到dest+count-1这段内存空间中每个字节都写成c。

下面这个例子是我从MSDN里拷的:

Example

/* MEMSET.C: This program uses memset to
* set the first four bytes of buffer to "*".
*/

#include <memory.h>
#include <stdio.h>

void main( void )
{
char buffer[] = "This is a test of the memset function";

printf( "Before: %s\n", buffer );
memset( buffer, '*', 4 );
printf( "After: %s\n", buffer );
}

Output

Before: This is a test of the memset function
After: **** is a test of the memset function