Hàm memset gán giá trị c cho n byte đầu của vùng nhớ

void *memset(void *dest, int c, size_t count);

Parameter:

dest: vùng nhớ cần gán giá trị

c: giá trị cần gán cho dest

count: cần gán c cho bao nhiêu byte của dest.

Remark:

Hàm memset( ) gán giá trị c cho count byte đầu của dest.

  • Hàm trả về con trỏ tới dest.

Ví dụ:

#include "stdio.h"
#include "conio.h"
#include "string.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 );

    getch();
}

Kết quả:

Hàm memset gán giá trị c cho n byte đầu của vùng nhớ
Hàm memset gán giá trị c cho n byte đầu của vùng nhớ

Be the first to comment

Leave a Reply