Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/myscript/public_html/classes/classdb.php on line 42
memset() - Fill Memory Block - C++ Buffer Manipulation Function Tutorial

memset() - Buffer Manipulation Function

How to fill memory block in C++?


memset() buffer manipulation function fills the first "num" bytes of memory block pointed by the pointer "ptr" to the specified "value". It returns the "ptr" value.


void * memset ( void * ptr, int value, size_t num );

Example :

#include <stdio.h>
#include <string.h>
int main ()
char str1[] = " is an encylopedia";
memset (str1,'*',4);
puts (str1);
return 0;

Result :

**** is an encylopedia

In the above example, "memset()" is used to fill the first "4" bytes of the memory block "str1" with "*". This buffer manipulation function replaces the 4 characters by the symbol.

C++ Tutorial

Ask Questions

Ask Question