关于 memset() 函数的用法

来自百度知道:http://zhidao.baidu.com/question/48460292.html

在你申请了一块内存之后,
比如 int *p=NULL; p=malloc(10*sizeof(int));//申请了10个int型内存
memset(p,0,10*sizeof(int));//全部初始化为0
memset的作用就是把你快连续的内存初始化为你给的值。
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

posted on 2012-12-27 15:47  代大伟  阅读(147)  评论(0)    收藏  举报

导航